merge from qinghaihu branch, add recursive dir function

This commit is contained in:
wlx 2012-10-31 03:39:39 +00:00
parent 8eb4c55d9c
commit 4e42811648
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 array_flat($array)
{
foreach($array as $a)
{
if(is_array($a))
{
$tmp = array_merge($tmp, $this->array_flat($a));
}else {
$tmp[] = $a;
}
}
return $tmp;
}
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);
}
}