note 23845 added to ref.dir
| From: | shadowt@php.net | Date: | Tue, 30 Jul 2002 06:18:07 +0000 |
| Subject: | note 23845 added to ref.dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33965@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....
--
http://www.php.net/manual/en/ref.dir.php
http://master.php.net/manage/user-notes.php?action=edit+23845
http://master.php.net/manage/user-notes.php?action=delete+23845
http://master.php.net/manage/user-notes.php?action=reject+23845