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

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

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

function list_dir($dirpath){   
    if($dirpath[strlen($dirpath)-1]!="\\"){$dirpath.="\\";}   
    static $result_array=array();   
    if(is_dir($dirpath)){   
        $handle=opendir($dirpath);   
        while($file=readdir($handle)){   
            if($file=="."||$file==".."){continue;}   
            if(is_dir($dirpath.$file)){   
                list_dir($dirpath.$file."\\");   
            }else{   
                array_push($result_array,$dirpath.$file);   
            }   
        }   
        closedir($handle);   
    }   
    return $result_array;   
 }   
  
 $array=list_dir("D:\www");   
 foreach($array as $value){   
    echo $value;   
    echo "<br>";   
 }

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