Traverse all files and folders in a folder php code

WBOY
Release: 2016-07-25 08:45:16
Original
858 people have browsed it

php traverses all files and folders under a certain folder

  1. function list_dir($dirpath){
  2. if($dirpath[strlen($dirpath)-1]!="\"){$dirpath.= "\";}
  3. static $result_array=array();
  4. if(is_dir($dirpath)){
  5. $handle=opendir($dirpath);
  6. while($file=readdir($handle)){
  7. if( $file=="."||$file==".."){continue;}
  8. if(is_dir($dirpath.$file)){
  9. list_dir($dirpath.$file."\");
  10. }else{
  11. array_push($result_array,$dirpath.$file);
  12. }
  13. }
  14. closedir($handle);
  15. }
  16. return $result_array;
  17. }
  18. $array=list_dir("D:www");
  19. foreach($array as $value){
  20. echo $value;
  21. echo "
    ";
  22. }
Copy code

php


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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!