Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- print_files(__DIR__);
- /**
- * @param $dirname Путь до директории
- * @param int $level Уровень вложености
- */
- function print_files($dirname, $level = 0){
- $dir = opendir($dirname);
- while (($item = readdir($dir)) !== false) {
- if ($item === '.' || $item === '..'){
- // Пропускаем служебные директрии
- continue;
- }
- // отступ
- $intend = $level > 0 ? str_repeat(' ', 4 * ($level - 1)) . '| ' : '';
- echo $intend. $item . PHP_EOL;
- if (is_dir($dirname . '/' . $item)) {
- // Рекурсивно выводим все поддиректории
- print_files($dirname . '/' . $item, $level + 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment