TREE command

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi folks,
I notice both unix and windows have the tree command for viewing a systems
files from the current dir downwards. Is there anyway in PHP which I could
use this command and make a tree with all the directories clickable? So
users could go to them directories?

Or what are others ways for navigation, basically one function I have for
instance is copy, a user selects a file to copy and on the next screen is
presented with a textbox to type wheer to copy in. It would be nice if I
could have something graphically for them to click on and then update the
box. Anyknow know anything on this or resources, anything in PEAR?

Thanks in advance.

Re: TREE command

Quoted text here. Click to load it

 May you could, but often it's better and safer to stick with native functions
rather than spawning external processes. See:


 And use an array as a stack to read any subdirectories. e.g.

$baseDir = '.';
$dirStack = array($baseDir);

while (($currentDir = array_pop($dirStack)) !== null)
    if ($dir = opendir($currentDir))
        while (($file = readdir($dir)) !== false)
            if ($file != '.' && $file != '..')
                if (is_dir("$currentDir/$file"))
                    array_push($dirStack, "$currentDir/$file");

                echo htmlspecialchars("$currentDir/$file") . "<br>";

< Space: disk usage analysis tool

Re: TREE command

Ner dont reinvent the wheel /

Re: TREE command

Thanks guys for them two repies, I will look into them both. I'm a bit
confused about phptree though, I wnet to that link and seen the navigation,
yes this is something like what I want but I don't want all the other stuff
with it. Maybe i'll be able to lift some good code out. Thanks again.

Quoted text here. Click to load it

Site Timeline