用于创build“漂亮”目录树的ASCII库?

是否有一些* nix工具或perl / php库,可以让你轻松创build目录树可视化,看起来像下面?

www |-- private | |-- app | | |-- php | | | |-- classes | | | +-- scripts | | |-- settings | | +-- sql | +-- lib | +-- ZendFramework-HEAD +-- public |-- css |-- images +-- scripts 

如何从Unix树/ Linux树的这个例子:

 ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' 

该oneliner是非常酷,我建议使用 util。

 bash-3.2$ mkdir -p this/is/some/nested/example bash-3.2$ mkdir -p this/is/another/super/nested/example bash-3.2$ mkdir -p this/is/yet/another/example bash-3.2$ mkdir -p this/is/some/nested/other/example bash-3.2$ tree this this `-- is |-- another | `-- super | `-- nested | `-- example |-- some | `-- nested | |-- example | `-- other | `-- example `-- yet `-- another `-- example 13 directories, 0 files 

请参阅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 … 

我意识到这个问题在很久以前就已经回答了,但是我刚刚发现了这个叫做tree的程序,它也很酷。

很酷的Python脚本来做到这一点: http : //code.activestate.com/recipes/217212/

看看App :: Asciio