add recursive dir function

This commit is contained in:
wlx 2012-09-18 04:06:31 +00:00
parent c02cff9004
commit 2fa74a0763
1 changed files with 38 additions and 0 deletions

View File

@ -33,5 +33,43 @@ class mydir{
function getLast()
{
return $this->list[count($this->list)-1];
}
function recursive($dir)
{
$files = array();
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
if(is_dir($dir.'/'.$file))
{
$dir2 = $dir.'/'.$file;
$files[]=$dir2;
$files[] = $this->recursive($dir2);
} else {
$files[] = $dir.'/'.$file;
}
}
}
closedir($handle);
}
return $this->array_flat($files);
}
function array_flat($array)
{
foreach($array as $a)
{
if(is_array($a))
{
$tmp = array_merge($tmp, array_flat($a));
}else {
$tmp[] = $a;
}
}
return $tmp;
}
}