ASCII Library for Creating “Pretty” Directory Trees?

后端 未结 10 1095
时光说笑
时光说笑 2020-12-04 07:33

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

www
|-- private
|             


        
10条回答
  •  情话喂你
    2020-12-04 08:04

    See the RecursiveTreeIterator class

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

    $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:\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
    …
    

提交回复
热议问题