ASCII Library for Creating "Pretty" Directory Trees?
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
| |-- app
| | |-- php
| | | |-- classes
| | | +-- scripts
| | |-- settings
| | +-- sql
| +-- lib
| +-- ZendFramework-HEAD
+-- public
|-- css
|-- images
+-- scripts
How about this example from Unix Tree / Linux Tree:
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
That oneliner is pretty cool, I'd recommend using the 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
I realize this question was answered ages ago, but I just found this program called tree which is pretty cool too.
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
…
exa with --tree does an excellent job:
exa --tree ~/tmp/public/
<dir>
├── aboutme
│ └── index.html
├── atrecurse
│ └── index.html
├── base.css
├── html5
│ ├── cat-and-mouse
│ └── frantic
│ ├── css
│ │ └── main.css