note 45767 added to function.opendir
| From: | cnichols at nmu dot edu | Date: | Fri, 17 Sep 2004 18:03:33 +0000 |
| Subject: | note 45767 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76893@lists.php.net to get a copy of this message | ||
Here's another recursive function that prints out everything from the starting path to the end.
It doesn't have any search function, but just another example. I wrote it for getting a quick
hierarchial view of websites (even through Dreamweaver will show it to me, it'd be a chore to
go through each folder and expand it).
<?php
// map_dirs(path,level)
// path, level to start (start at 0)
map_dirs("/var/ww/html/",0);
function map_dirs($path,$level) {
if(is_dir($path)) {
if($contents = opendir($path)) {
while(($node = readdir($contents)) !== false) {
if($node!="." && $node!="..") {
for($i=0;$i<$level;$i++) echo " ";
if(is_dir($path."/".$node)) echo "+";
else echo " ";
echo $node."\n";
map_dirs("$path/$node",$level+1);
}
}
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45767
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45767&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45767&report=yes
Search -- http://master.php.net/manage/user-notes.php