English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

is there any script to display all files and directories and files in subdirectories of a given directory

2006-09-20 03:10:28 · 3 answers · asked by Mohammad Shahid 1 in Computers & Internet Programming & Design

3 answers

do you want to do this recursively?

the best way to list all files, directories, and subdirectories, etc. is to do like the first person described at first, except use a function:

function listDirectory( $dirName ){
$dirHandle = null;
$dirHandle = opendir( $dirName );
while ($name = readdir( $dirHandle ) ){ //this will fail as soon as readdir returns false
echo $name."
";
if isdir( $dirName."/".$name ){ listDirectory( $dirName."/".$name );}
}
}

Using the system() function is usually insecure so it is usually disabled, but it can be enabled if that is the path you want to go. The above code, however, is system independant and only relies on read permissions on the checked directories.

2006-09-20 04:25:34 · answer #1 · answered by John J 6 · 0 0

Yes

if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo $file;
}
}
closedir($handle);
}
?>

Put this code in the directory you want to view your files from, or assign the appropriate directory in the opendir('.')) function, and open the index.php file in your browser.

You may need to adjust your folder permission to use this. Not sure.

2006-09-20 10:59:28 · answer #2 · answered by rob 3 · 0 0

A faster way is to use the php function system().
All you have to know is
- the operating system on the webserver
- if the webserver allows you to use this php function

Windows:
echo "

";
system("dir");
echo "
"
?>

Linux:
echo "
";
system("ls");
echo "
";
?>

Use system when you want to execute a server-side command.
If the server has implemented the "tree" command, you can use it like this:

system("tree");
?>

2006-09-20 11:16:54 · answer #3 · answered by simpaticool86 2 · 0 0

fedest.com, questions and answers