[#6]
msh at onliners dot dk [2006-01-30 03:49:01]
I would like to present these two simple functions for generating a complete directory listing - as I feel the other examples are to restrictive in terms of usage.
function dirTree($dir) {
$d = dir($dir);
while (false !== ($entry = $d->read())) {
if($entry != '.' && $entry != '..' && is_dir($dir.$entry))
$arDir[$entry] = dirTree($dir.$entry.'/');
}
$d->close();
return $arDir;
}
function printTree($array, $level=0) {
foreach($array as $key => $value) {
echo "
if(is_array($value))
printTree($value, $level+1);
}
}
Usage is as simple as this:
$dir = "";
$arDirTree = dirTree($dir);
printTree($arDirTree);
It is easy to add files to the tree also - so enjoy.