note 61335 deleted from function.readdir by nlopess
| From: | nlopess@php.net | Date: | Tue, 31 Jan 2006 23:03:22 +0000 |
| Subject: | note 61335 deleted from function.readdir by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-102795@lists.php.net to get a copy of this message | ||
Note Submitter: cart at kolix dot de
----
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($pic);
}
?>
Start with:
<?php
$path="path/to/your/dir";
read_dir($path);
?>