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

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

PHP中文网
PHP中文网Original
2016-05-25 17:15:441118browse

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 "
";   
 }

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