<?php
/**
*递归遍历文件
*@param string $path目录地址(路径)
*@param int $deep = 0 递归调用的深度
*/
function readDirs($path, $deep = 0){
//打开文件句柄
$dir_handle = opendir($path);
while (false !== $file = readdir($dir_handle)) {
if ($file == '.' || $file == '..') {
continue;
}
//输出文件名
echo str_repeat(' ', $deep * 2) . $file,'<br />';
//判断当前文件是否又是一个目录
if (is_dir($path . '/' . $file)) {
readDirs($path . '/' . $file, $deep + 1);
}
}
}
//调用递归目录函数
readDirs('./');
遍历目录下所有的文件
最新推荐文章于 2022-12-05 10:30:48 发布