Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用于创建“ASCII”的库;“漂亮”;目录树?_Php_Unix_Tree_Ascii - Fatal编程技术网

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

Php 用于创建“ASCII”的库;“漂亮”;目录树?,php,unix,tree,ascii,Php,Unix,Tree,Ascii,是否有一些*nix工具或perl/php库可以让您轻松创建如下所示的目录树可视化 www |-- private | |-- app | | |-- php | | | |-- classes | | | +-- scripts | | |-- settings | | +-- sql | +-- lib | +-- ZendFramework-HEAD +-- public |-- c

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

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

这个例子来自:

看看

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

参见课程

允许在递归迭代器上迭代以生成ASCII图形树

输出如下(在我的机器上使用c:\php):


很酷的Python脚本:

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
做得很好:

exa --tree ~/tmp/public/

<dir>
├── aboutme
│  └── index.html
├── atrecurse
│  └── index.html
├── base.css
├── html5
│  ├── cat-and-mouse
│  └── frantic
│     ├── css
│     │  └── main.css
exa--tree~/tmp/public/
├── 关于我
│  └── index.html
├── 阿勒库斯
│  └── index.html
├── base.css
├── html5
│  ├── 猫和老鼠
│  └── 疯狂的
│     ├── css
│     │  └── main.css

本身不是一个库,但这个小实用程序可以方便地生成快速树形图,而无需离开浏览器:


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

[php]调整树符号,取自


近年来,这方面的进展很大。软件包管理器中的linux版本更干净,颜色更鲜艳:

Debian/Ubuntu:

sudo apt install tree
CentOS/RHEL/OpenSUSE:

sudo yum install tree
如果您的
当前\u目录结构有一个庞大的子目录,并且只想显示该结构包含的内容示例,则可以执行以下操作:

tree -P *my_own_pattern_to_find* current_directory

你一定会喜欢单线的,这让人恶心,但我喜欢上面的输出的一部分是,它不是所有的破折号到文件,你让那些管道垂直连接子目录,然后你可能会检查这个人的解决方案:太好了!虽然输出不太正确(我不是在批评,而是在添加构造性批评)-但在我尝试时,子目录中的文件都被分组在一起了?有人知道如何添加到该脚本中,以便它也显示目录中的文件吗?这应该被标记为正确答案。它支持DirColor,并且输出布局更为美观。对于Mac OS X用户来说,它甚至也是一个macport。
tree
也可以使用自制软件安装,适用于那些从Macports迁移过来的用户。需要注意的是,对于Windows,您只需在命令行中键入
tree
。不需要安装任何东西。对于Mac电脑上的那些,
brew install tree
我很难使用特殊字符作为默认字符的tree,但是来自的建议是使用
tree--charset=ASCII
,这样tree就可以生成上面user1116793示例中的字符。它也有一些创造性的用途。我用它来可视化我的差事(大多数工具都没有真正的分层功能,甚至Jira也没有)。如果有人在Windows上寻找这个解决方案(我是!),你只需在命令行中键入
tree
。这么晚才找到,但这太棒了!为特定类型的项目和
exa-T-D
开发一个生成文件树的工具非常有用。谢谢
<?php
$path = './targetdir';
$unicodeTreePrefix = function(RecursiveTreeIterator $tree){
  $prefixParts = [
      RecursiveTreeIterator::PREFIX_LEFT         => ' ',
      RecursiveTreeIterator::PREFIX_MID_HAS_NEXT => '+ ',
      RecursiveTreeIterator::PREFIX_END_HAS_NEXT => '├ ',
      RecursiveTreeIterator::PREFIX_END_LAST     => '└ '
    ];
  foreach ($prefixParts as $part => $string) {
      $tree->setPrefixPart($part, $string);
  }
};
$dir  = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_FILENAME | RecursiveDirectoryIterator::SKIP_DOTS);
$tree = new RecursiveTreeIterator($dir);
$unicodeTreePrefix($tree);
echo "<br><br>";
echo "[$path]<br>";
foreach ($tree as $filename => $line) {
  echo $tree->getPrefix(), $filename, "<br>";
}
sudo apt install tree
sudo yum install tree
tree -P *my_own_pattern_to_find* current_directory