[php]调整树符号,取自https://gist.github.com/hakre/3599532
<?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>";
}
输出示例
[./targetdir]<br> ├ aHR0cHM<br> ├ gtyyu.txt<br> ├ Screenshot at 2020-05-28 22-23-30.png<br> ├ 2004 - Synchrone<br> + ├ 09-Live for willyman.mp3<br> + ├ 04-Inabox.mp3<br> + ├ 05-Trashastan.mp3<br> + ├ 07-Nordick.mp3<br> + ├ 08-Rupture.mp3<br> + ├ Best of<br> + + ├ 08 - Civil War.mp3<br> + + ├ 09 - 14 Years.mp3<br> + + ├ 05 - Welcome To The Jungle.mp3<br> + + ├ 06 - Don't Cry.mp3<br> + + ├ 04 - Sweet Child O' Mine.mp3<br> + + ├ 02 - Paradise City.mp3<br> + + ├ 07 - Yesterdays.mp3<br> + + ├ 03 - Patience.mp3<br> + + ├ 01 - November Rain.mp3<br> + + └ 10 - Estranged.mp3<br> + ├ 03-Sarangui.mp3<br> + ├ 06-The test.mp3<br> + ├ 01-Sabradub.mp3<br> + └ 02-L'uzure.mp3<br> ├ Screenshot at 2020-02-11 12-31-52.png<br> ├ trur.txt<br> ├ .hidden<br> + ├ .sub_article.txt<br> + └ sub_article_in_hidden.txt<br> ├ gtuitre.txt<br> ├ aHR0cHM.txt<br> ├ CREEP.mp3<br> ├ subfolder<br> + └ sub_article.txt<br> ├ filtle.txt<br> ├ Best of<br> + ├ 08 - Civil War.mp3<br> + ├ 09 - 14 Years.mp3<br> + ├ 05 - Welcome To The Jungle.mp3<br> + ├ 06 - Don't Cry.mp3<br> + ├ 04 - Sweet Child O' Mine.mp3<br> + ├ 02 - Paradise City.mp3<br> + ├ 07 - Yesterdays.mp3<br> + ├ 03 - Patience.mp3<br> + ├ 01 - November Rain.mp3<br> + └ 10 - Estranged.mp3<br> ├ Screenshot at 2020-05-12 14-51-56.png<br> ├ of.txt<br> ├ highlight.css<br> └ Screenshot at 2020-06-10 19-28-51.png<br>
tree
在命令行中键入即可。