note 61336 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 19:01:38 +0000 |
| Subject: | note 61336 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126516@lists.php.net to get a copy of this message | ||
Note Submitter: cart at kolix dot de
----
*updated version
Here is my recursive read_dir function. It sorts directories and files alphabetically.
<?php
function read_dir($dir) {
$path = opendir($dir);
while (false !== ($file = readdir($path))) {
if($file!="." && $file!="..") {
if(is_file($dir."/".$file))
$files[]=$file;
else
$dirs[]=$dir."/".$file;
}
}
if($dirs) {
natcasesort($dirs);
foreach($dirs as $dir) {
echo $dir;
read_dir($dir);
}
}
if($files) {
natcasesort($files);
foreach ($files as $file)
echo $file
}
closedir($path);
}
?>
Start with:
<?php
$path="path/to/your/dir";
read_dir($path);
?>