我想递归遍历一个目录,然后让结果呈树形结构展示出来,请高手指点下。下面是遍历函数
php code$file){ if($file == . || $file == ..){ continue; } if(is_dir($path./.$file)){ echo $path./.$file. -- dir
; ergfile($path./.$file); }else{ echo $path./.$file.
; } } }ergfile($path);?>
如何让他以树形结构显示呢?
a -- dir
a.tx
a1.exe
a1 -- dir
aa.txt
bb.exe
b --dir
b2 -- dir
b3 -- dir
b3b.txt
b4g.exe
..........
------解决方案--------------------
在 echo 后面插入 str_repeat(' ', substr_count($path, '/')) .
