Home > php教程 > PHP源码 > 遍历某文件夹下的所有文件和文件夹方法二

遍历某文件夹下的所有文件和文件夹方法二

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

php代码

/*用到了scandir这个函数*/
function list_dir($dirpath){   
    if($dirpath[strlen($dirpath)-1]!='/'){   
        $dirpath.="/";   
    }   
    static $result_array=array();   
    if(is_dir($dirpath)){   
        $files_dirs=scandir($dirpath);   
        foreach($files_dirs as $file){   
            if($file=='.'||$file=='..'){continue;}   
            if(is_dir($dirpath.$file)){   
                list_dir($dirpath.$file);   
            }else{   
                array_push($result_array,$dirpath.$file);   
            }   
        }   
    }   
    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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template