note 71758 deleted from function.scandir by felipe
| From: | felipe@php.net | Date: | Fri, 29 Aug 2008 23:25:40 +0000 |
| Subject: | note 71758 deleted from function.scandir by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144003@lists.php.net to get a copy of this message | ||
Note Submitter: evert_18 at hotmail dot com
----
A nice function to read a dir, with unlimited subdirs and files, it will create an array with files
and dirs (tree structure).
<?php
function dirlist($dir) {
foreach(scandir($dir) as $entry)
if($entry != '.' && $entry != '..')
{
$entry = $dir.'/'.$entry;
if(is_dir($entry))
{
$path = pathinfo($entry);
$listarray[$path['basename']] = dirlist($entry);
}
else
{
$path = pathinfo($entry);
$listarray[] = $path['basename'];
}
}
return($listarray);
}
?>