An easy way would be to to convert your code to a function and use
recursion with an is_dir conditional.
Here is a quick example, there are also a few examples in the user notes
at the PHP manual for opendir or readdir.
function lsdir($dir) {
if ($handle = opendir($dir)) {
while false !==($filename = readdir($handle)) {
if (is_dir($dir . '/' . $filename)) {
lsdir($dir . '/' . $filename);
} elseif (is_file($dir . '/' . $filename) && $filename != '.'
&&
$filename != '..') {
// file display code here
}
}
closedir($dir);
}
}
I did not run the above code, just typed it for an example so the code
itself may or may not work but the concept will work.
Jason
On Mon, 2003-02-03 at 17:14, Tomas Vorobjov wrote:
> hey!
>
> this is the code I'm using to get into array all filenames in a directory:
>
>
> $mydir = mydir //the directory name
> $output_file = fopen($data_file, "w");
> $begin = " \$files_name = array(";
>
> fwrite($output_file, $begin);
>
> $output_file = fopen($data_file, "w");
> if ($handle = opendir('./$mydir/')) {
> while (false !== ($filename = readdir($handle))) {
> if ($file != "." && $filename != "..") { //&& !is_dir($filename)
> can be added
> $element = "\"$filename\",";
> fwrite($output_file, $element);
> }
> }
> closedir($handle);
> }
> fwrite($output_file,"\"\");\r\n");
> fwrite($output_file, "?>");
> fclose($output_file);
>
> chmod($output_file, 0777); //to preview
>
> echo "the list has been succesfully created";
>
>
> now, how can I make the script to look into subdirectories of ./$mydir/
> and output also those filenames into the same or another array?
>
> thank you
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php