shelix/scripts/Tree
2024-02-26 00:37:44 +01:00

44 lines
2.2 KiB
PHP
Executable File

#!/usr/bin/php
<?php
/*
╔-----------------------------------------------------------------------╗
║ ║
║ This file is part of the Shelix IDE. ║
║ Copyright (C) 2024 NVRM webdev23 https://github.com/webdev23 ║
║ ║
║ This program is free software: you can redistribute it and/or modify ║
║ it under the terms of the GNU General Public License as published by ║
║ the Free Software Foundation, either version 3 of the License, or ║
║ (at your option) any later version. ║
║ ║
║ This program is distributed in the hope that it will be useful, ║
║ but WITHOUT ANY WARRANTY; without even the implied warranty of ║
║ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ║
║ GNU General Public License for more details. ║
║ ║
║ You should have received a copy of the GNU General Public License ║
║ along with this program. If not, see <http://www.gnu.org/licenses/>. ║
╚-----------------------------------------------------------------------╝*/
$path = getcwd();
$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 PHP_EOL;
echo "[$path]" . PHP_EOL;
foreach ($tree as $filename => $line) {
echo $tree->getPrefix(), $filename, PHP_EOL;
}