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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1581559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:09:53  来源:igfitidea点击:

ASCII Library for Creating "Pretty" Directory Trees?

phpunixtreeascii

提问by Alan Storm

Is there some *nix tool or perl/php library that will let you easily create directory tree visualizations that look like the following?

是否有一些 *nix 工具或 perl/php 库可以让您轻松创建如下所示的目录树可视化?

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

回答by bobbymcr

How about this example from Unix Tree / Linux Tree:

Unix Tree / Linux Tree 中的这个例子怎么样:

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

回答by user1116793

That oneliner is pretty cool, I'd recommend using the treeutil.

那个oneliner非常酷,我建议使用treeutil。

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

回答by Ibrahim

I realize this question was answered ages ago, but I just found this program called treewhich is pretty cool too.

我意识到这个问题很久以前就有人回答了,但我刚刚发现这个名为tree 的程序也很酷。

回答by Gordon

See the RecursiveTreeIteratorclass

RecursiveTreeIterator班级

Allows iterating over a RecursiveIterator to generate an ASCII graphic tree.

允许迭代 RecursiveIterator 以生成 ASCII 图形树。

$treeIterator = new RecursiveTreeIterator(
    new RecursiveDirectoryIterator('/path/to/dir'),
    RecursiveTreeIterator::SELF_FIRST);

foreach($treeIterator as $val) echo $val, PHP_EOL;

Output will be something like this (with c:\php on my machine):

输出将是这样的(在我的机器上使用 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
…

回答by andy boot

exa with --treedoes an excellent job:

exa with --tree做得很好:

exa --tree ~/tmp/public/

<dir>
├── aboutme
│  └── index.html
├── atrecurse
│  └── index.html
├── base.css
├── html5
│  ├── cat-and-mouse
│  └── frantic
│     ├── css
│     │  └── main.css

回答by Nathan Friend

Not a library per se, but this little utility is handy for generating quick tree graphs without leaving the browser: https://tree.nathanfriend.io/

本身不是一个库,但这个小实用程序可以方便地在不离开浏览器的情况下生成快速树图:https: //tree.nathanfriend.io/

Disclaimer: I'm the author :).

免责声明:我是作者:)。

回答by zcopley

Cool Python script to do it: http://code.activestate.com/recipes/217212/

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

回答by draegtun

Have a look at App::Asciio 

看看App::Asciio