Home > Backend Development > PHP Tutorial > Traverse all files and folders under a folder Method 5

Traverse all files and folders under a folder Method 5

WBOY
Release: 2016-07-25 09:11:38
Original
854 people have browsed it
Traverse all files and folders under a 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


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