note 45928 deleted from function.opendir by aidan
| From: | aidan@php.net | Date: | Fri, 24 Sep 2004 01:34:39 +0000 |
| Subject: | note 45928 deleted from function.opendir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77290@lists.php.net to get a copy of this message | ||
Note Submitter: brjpeter at iupui dot edu
----
Here is a nice function to return a list of every file (recursively) in a directory.
<?php
function listfiles($dir)
{
$i = -1;
if(is_dir($dir))
{
$dl = opendir($dir);
if($dl)
{
while($file = readdir($dl))
{
$list = $dir . "/" . $file;
if(is_dir($list))
{
if($file != "." && $file !=
"..")
{
$i++;
$arr = listfiles($list);
for($j = 0; $j < sizeof($arr); $j++)
{
$array[$i + $j] = $arr[$j];
}
$i += sizeof($arr) - 1;
}
}
else
{
$i++;
$array[$i] = $dir . "/". $file;
}
}
}
closedir($dl);
}
return $array;
}
?>
Hope it helps anyone looking for that type of function. It seems fast enough.