見RecursiveTreeIterator
類
允許迭代一個RecursiveIterator生成一個ASCII圖形樹。
$treeIterator = new RecursiveTreeIterator(
new RecursiveDirectoryIterator('/path/to/dir'),
RecursiveTreeIterator::SELF_FIRST);
foreach($treeIterator as $val) echo $val, PHP_EOL;
輸出會是這樣(用C:\ PHP我的機器上):
|-c:\php5\cfg
|-c:\php5\data
| |-c:\php5\data\Base
| | \-c:\php5\data\Base\design
| | |-c:\php5\data\Base\design\class_diagram.png
| | \-c:\php5\data\Base\design\design.txt
| |-c:\php5\data\ConsoleTools
| | \-c:\php5\data\ConsoleTools\design
| | |-c:\php5\data\ConsoleTools\design\class_diagram.png
| | |-c:\php5\data\ConsoleTools\design\console.png
| | |-c:\php5\data\ConsoleTools\design\console.xml
…
如果有人在Windows上尋找這個解決方案(我是!),只需在命令行鍵入'tree'即可。 –