Home > php教程 > PHP源码 > 遍历某文件夹下的所有文件和文件夹 方法六(请无视)

遍历某文件夹下的所有文件和文件夹 方法六(请无视)

PHP中文网
Release: 2016-05-25 17:15:44
Original
1179 people have browsed it

php代码

 function list_dir($dirpath){   
    if($dirpath[strlen($dirpath)-1]!="\\"){$dirpath.="\\";}   
    static $result_array=array();   
    if(is_dir($dirpath)){   
        $dir=dir($dirpath);   
        while($file=$dir->read()){   
            if($file=="."||$file==".."){continue;}   
            if(is_dir($dirpath.$file)){   
                list_dir($dirpath.$file."\\");   
            }else{   
                array_push($result_array,$dirpath.$file);   
            }   
        }   
        $dir->close();   
    }   
    return $result_array;   
 }   
  
 $array=list_dir("D:\www");   
 foreach($array as $value){   
    echo $value;   
    echo "
";   
 }
Copy after login

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template