Forum Moderators: coopster
What i need is a script which will read directories and sub directories and out put them to a menu
example
Directory structure
MainDir
¦-SubDir
¦---Subsubdir
¦-Subdir2
¦---Subsubdir2
I would like it output like that too so u can see the subdir is under the parent dir. the best i got so far is it to put the list of dirs but not in order or in any structure. I am sure there has to be a function to do it somewhere? :)
something like:
[pre]function tree($dir, $depth, &$tree) {
if ($handle = opendir($dir)) {
$depth++;
while (false!== ($file = readdir($handle))) {
if(!is_dir("$dir/$file") continue;
$tree[] = array("dir" => $file, "depth" => $depth)echo "$file\n";
tree("$dir/$file", $depth, &$tree);
}
closedir($handle);
}
and call the function as:
$basedir = "/var/www/htdocs/example.com";
$depth = 0;
$tree = array();
tree($basedir, $depth, $tree);
then in $tree[0]['dir'] you have the directory
and in $tree[0]['depth'] you have the depth
In the beginning don't forget to create a watchdog - eg. end script on 1000 dir, so you don't have a neverending loop
Hope this is what you looked for
Michal
Michal
PS. I wonder how many errors there were ;)