PHP文件遍历小例子 完整代码: $dir = "D:workspace"; function list_file($dir = '.'){ $list = scandir($dir); echo ''; foreach($list as $file){ $target = "$dir/$file"; if ( is_dir($target) && $file != '.' && $file != '..' ){ echo "$file"; list_file($target); } else if ( $file != '.' && $file != '..'){ echo "$file"; } } echo ''; } list_file($dir); 复制代码