$dir = 'E:\AppServ\www\alpaca\app';
//递归生成目录树
function recurDir($pathName) {
$result = array();
$tmp = array();
if( !is_dir($pathName) || !is_readable($pathName) ){
return null;
}
$allFiles = scandir($pathName);
foreach($allFiles as $fileName){
if( in_array($fileName, array('.', '..')) ) continue;
$fullName = $pathName . '/' . $fileName;
if( is_dir($fullName) ){
$result[$fileName] = recurDir($fullName);
}else{
$temp[] = $fileName;
}
}
if($temp){
foreach( $temp as $f ){
$result[] = $f;
}
}
return $result;
}
//递归遍历生成目录
//www.jbxue.com
function bl($arr, $l = '-|'){
static $l = '';
static $str = '';
foreach($arr as $key=>$val){
if(is_array($arr[$key])){
//echo $val . "
";
//echo $l . $key . "
";
$str .= $l . $key . "
";
$l .= '-|';
bl($arr[$key], $l);
}else{
//echo $l . $val . "
";
$str .= $l . $val . "
";
}
}
$l = '';
return $str;
}
$tree = recurDir($dir);
echo "
";
print_r($tree);
echo "
";echo "
------------------------------------------
";
$data = bl($tree);
echo "
";
print_r($data);
echo "
";