php遍历目录

function traverse($path = ‘.’) {
$current_dir = opendir($path);    //opendir()返回一个目录句柄,失败返回false
while(($file = readdir($current_dir)) !== false) {    //readdir()返回打开目录句柄中的一个条目
$sub_dir = $path . “/” . $file;    //构建子目录路径
if($file == ‘.’ || $file == ‘..’) {
continue;
} else if(is_dir($sub_dir)) {    //如果是目录,进行递归
echo ‘Directory ‘ . $file . ‘:<br>’;
traverse($sub_dir);
} else {    //如果是文件,直接输出
$x = ” . $path . ‘/’ . $file . ”;
$y = str_replace(array(“截图”,”爆款”,”未命名”,”评价”,”图片”),array(‘JieTu’,’BaoKuan’,’NnNn’,’PingJia’,’TuTuTu’),$x);
echo $x.'<br />’;
//echo $y.'<br />’;
//rename($x, $y);

}
}
}


发表评论 0

Your email address will not be published. Required fields are marked *