note 23845 deleted from ref.dir by dams
| From: | dams@php.net | Date: | Tue, 30 Jul 2002 10:57:43 +0000 |
| Subject: | note 23845 deleted from ref.dir by dams | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-33974@lists.php.net to get a copy of this message | ||
hi everyone!
i needed a function that was capable of listing only directories (where the structure of the
dir-tree can be visualized), and found it rather hard to realize. since i'm quite inexperienced
in php i would like to ask any of you to review the following code and tell me if there are any
grave mistakes in it, thank you very much!
function list_dirs($root, $sep){
if ($root[strlen($root)-1]!="/"){
$root[strlen($root)]="/";
}
clearstatcache();
if (is_dir($root)){
$handle=opendir($root) or die ("No valid handle");
while (false!==($next=readdir($handle))){
clearstatcache();
if ($next!="." && $next!=".." && is_dir($root.$next)){
echo $sep." ".$root.$next."<br>";
//for instance, you can add any code you feel apropriate here
list_dirs($root.$next,$sep.$sep);
}
}
closedir($handle);
}
}
where $sep is any kind of separator, like " " if you use this function inside <pre>
tags, as is supposed to....