Ala*_*orm 70 php unix tree ascii
是否有一些*nix工具或perl/php库可以让您轻松创建如下所示的目录树可视化?
www
|-- private
| |-- app
| | |-- php
| | | |-- classes
| | | +-- scripts
| | |-- settings
| | +-- sql
| +-- lib
| +-- ZendFramework-HEAD
+-- public
|-- css
|-- images
+-- scripts
Run Code Online (Sandbox Code Playgroud)
bob*_*mcr 101
来自Unix Tree/Linux Tree的这个例子怎么样:
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
Run Code Online (Sandbox Code Playgroud)
小智 77
那个oneliner非常酷,我建议使用tree 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
Run Code Online (Sandbox Code Playgroud)
Gor*_*don 16
允许迭代RecursiveIterator以生成ASCII图形树.
$treeIterator = new RecursiveTreeIterator(
new RecursiveDirectoryIterator('/path/to/dir'),
RecursiveTreeIterator::SELF_FIRST);
foreach($treeIterator as $val) echo $val, PHP_EOL;
Run Code Online (Sandbox Code Playgroud)
输出将是这样的(在我的机器上使用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
…
Run Code Online (Sandbox Code Playgroud)
与--tree的exa表现出色:
exa --tree ~/tmp/public/
<dir>
??? aboutme
? ??? index.html
??? atrecurse
? ??? index.html
??? base.css
??? html5
? ??? cat-and-mouse
? ??? frantic
? ??? css
? ? ??? main.css
Run Code Online (Sandbox Code Playgroud)