欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

php递归所有文件

最编程 2024-02-20 22:05:58
...
 <?php
$files = listDir("thinkworld_v3");
function listDir($dirName)
{
if(is_dir($dirName))//是否目录
{
if($dh=opendir($dirName)) //打开
{
while(($file=readdir($dh)) !== false) //readdir成功,则返回一个文件名,否则返回 false。
{
if($file != "." && $file != "..") 
{
$filePath = $dirName . "/" . $file;
if(is_dir($filePath)) //为目录,递归 
{
$tree[$file] = listDir($filePath);

else //为文件,添加到当前数组 

$tree[] = $file; 
}
echo $filePath."<br/>";


closedir( $dh ); 
}
else 
{
echo "error";
}
//返回当前的$tree 
return $tree; 
}
else
{
echo "不为目录";
}
}


?> 

推荐阅读