Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function tree($path, $level = 0, $structure = '', &$onlyOnce = false)
- {
- $elements = scandir($path);
- $last = end($elements);
- reset($elements);
- $onlyOnce = true;
- foreach ($elements as $element) {
- if ($element[0] == '.') {
- continue;
- }
- $isLast = $element == $last;
- $currentStructure = $structure . ($isLast ? '`' : '|') . '-- ';
- echo $currentStructure.$element.PHP_EOL;
- $subpath = $path.DIRECTORY_SEPARATOR.$element;
- if (is_dir($subpath)) {
- $sep = $isLast ? ' ' : '| ';
- tree($subpath, $level+1, $structure.$sep, $onlyOnce);
- }
- if ($isLast && $onlyOnce) {
- echo $structure.PHP_EOL;
- $onlyOnce = false;
- }
- }
- }
- tree('../..');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement