note 45767 deleted from function.opendir by cmb
| From: | cmb@php.net | Date: | Tue, 11 Jun 2019 06:41:17 +0000 |
| Subject: | note 45767 deleted from function.opendir by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211227@lists.php.net to get a copy of this message | ||
Note Submitter: cnichols at nmu dot edu
----
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);
}
}
}
}
}
?>