By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

TREE command

P: n/a
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.
Dave
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 21 Dec 2004 22:07:47 -0000, "Dave" <co*****@akamarketing.com> wrote:
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?


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

opendir()
readdir()

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

<?php
$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>";
}
}
}
}
?>

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
Ner dont reinvent the wheel

http://phptree.sourceforge.net/

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.