Recursive opendir(), I am getting something wrong
Posted: Thu Jul 01, 2004 2:15 pm
I am trying to make a css stylesheet manager, one of the important steps to the realization of this progie is my idea to organize all stylesheets in a good directory tree. However the following script is causing me headaches. I think I am running into problems with my recursion as I somehow need to close the handler before I jump into the next subdirectory, but at the moment I cannot think of a better way, and I can't fix this one.
Thanks in advance,
Thanks in advance,
Code: Select all
function parse_css ($styles_root) {
echo($styles_root);
if (is_dir($styles_root)) { //If directory exist returns true
if ($dh = opendir($styles_root)) { //If directory is opened return true and assign $dh to that directory
while (($file = readdir($dh)) != false) { //Step through file listings
if ( ($file != '.') && ($file != '..') && ($file != '_vti_cnf') ) {
if (ereg ("css$", $file) ) { // Only load .css files
echo($file);
$handle = fopen ($file, "r");
$contents .= fread ($handle, filesize ($file));
fclose ($handle);
}
else if ( (is_dir($file)) ) {
parse_css($file . '/');
}
}
}
closedir($dh);
}
}
return( $contents );
}
$styles_root = $CFG['path_styles'];
parse_css($styles_root);