Home  >  Article  >  php教程  >  php遍历文件夹所有文件子文件夹函数代码

php遍历文件夹所有文件子文件夹函数代码

WBOY
WBOYOriginal
2016-06-06 20:26:181306browse

这篇文章主要介绍了php遍历文件夹所有文件子文件夹函数,大家参考使用

复制代码 代码如下:


function my_scandir($dir)
{
    $files=array();
    if(is_dir($dir))
     {
        if($handle=opendir($dir))
         {
            while(($file=readdir($handle))!==false)
             {
                if($file!="." && $file!="..")
                 {
                    if(is_dir($dir."/".$file))
                     {
                        $files[$file]=my_scandir($dir."/".$file);
                     }
                    else
                     {
                        $files[]=$dir."/".$file;
                     }
                 }
             }
            closedir($handle);
            return $files;
         }      
     }  
}
print_r(my_scandir("D:\Downloads\Firefox"));
?>

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