Home  >  Article  >  Backend Development  >  php visitFile()遍历指定文件夹函数_php技巧

php visitFile()遍历指定文件夹函数_php技巧

WBOY
WBOYOriginal
2016-05-17 09:23:22897browse

注:visitFile()有少量修改

复制代码 代码如下:


// 查看指定文件夹的文件
$fileList = array();
function visitFile($path)
{
global $fileList;
$path = str_replace("\\", "/", $path);
$fdir = dir($path);
while (($file = $fdir->read()) !== false)
{
if($file == '.' || $file == '..'){ continue; }
$pathSub = preg_replace("*/{2,}*", "/", $path."/".$file); // 替换多个反斜杠
$fileList[] = is_dir($pathSub) ? $pathSub."/" : $pathSub;
if(is_dir($pathSub)){ visitFile($pathSub); }
}
$fdir->close();
return $fileList;
}
?>



$path = str_replace("\\", "/", $path);
$path = preg_replace("*/{2,}*", "/", $path);
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn