note 15091 added to function.readdir.php
| From: | jp58782 at u dot washington dot edu | Date: | Mon, 27 Aug 2001 22:03:05 +0000 |
| Subject: | note 15091 added to function.readdir.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-17221@lists.php.net to get a copy of this message | ||
If you want to avoid using arrays, and still print out files in a tree recursively use something
like this:
<?php
function echo_dir($where) {
$handle = opendir('.');
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($file)) {
chdir($file);
echo_dir($file);
chdir("../");
} else {
if ($where != "") {
echo "$where/$file<br>";
} else {
echo "$file<br>";
}
}
}
}
closedir($handle);
}
echo_dir("");
?>
http://www.php.net/manual/en/function.readdir.php