- <?php
- function traverse($path = '.', $level = 0) {
- $current_dir = opendir($path);
- while(($file = readdir($current_dir)) != false) {
- $subdir = $path. DIRECTORY_SEPARATOR . $file;
- if ($file == '.' || $file == '..' || $file[0] == '.') {
- continue;
- } else if (is_dir($subdir)) {
- echo str_repeat(' ', $level) . $file."\\n";
- traverse($subdir, $level+1);
- } else if (is_file($subdir)) {
- echo str_repeat(' ', $level). $file. "\\n";
- }
- }
- }
- traverse();
- //该片段来自于http://www.codesnippet.cn/detail/0303201614585.html
来源: http://www.codesnippet.cn/detail/0303201614585.html