<?php
//遍历文件夹函数
function readAllFiles($strDir){
$arrFiles = array();
$resDir = opendir($strDir);
while (($file = readdir($resDir)) !== false) {
if($file != "." && $file != ".."){ //注意过滤掉.和..
$file = $strDir . DIRECTORY_SEPARATOR . $file; //注意$file全路径
if (is_dir($file)) {
$tmpArrFiles = readAllFiles($file);
$arrFiles = array_merge($arrFiles,$tmpArrFiles);
}else {
$arrFiles[] = $file;
}
}
}
return $arrFiles;
}
//调用函数遍历/www/tmp,返回所有文件
$strDir = "/www/tmp";
$arrFiles = readAllFiles($strDir);
foreach ($arrFiles as $strFile){
//进行操作
var_dump(__file__,__line__,$strFile);
}
?>
遍历目录及子目录(新浪)
最新推荐文章于 2023-07-02 16:03:15 发布