Home > Backend Development > PHP Tutorial > Method 3 to traverse all files and folders under a folder

Method 3 to traverse all files and folders under a folder

WBOY
Release: 2016-07-25 09:11:41
Original
855 people have browsed it
Traverse all files and folders under a folder
  1. function list_dir($dirpath){
  2. if($dirpath[strlen($dirpath)]-1!='/'){
  3. $dirpath.="/";
  4. }
  5. static $result_array=array( );
  6. if(is_dir($dirpath)){
  7. $files_dirs=scandir($dirpath);
  8. foreach($files_dirs as $file){
  9. if($file=='.'||$file=='. .'){continue;}
  10. if(is_dir($dirpath.$file)){
  11. list_dir($dirpath.$file);
  12. }else{
  13. array_push($result_array,$dirpath.$file);
  14. }
  15. }
  16. }
  17. return $result_array;
  18. }
  19. $array=list_dir('D:/www');
  20. foreach($array as $value){
  21. echo $value;
  22. echo "
    ";
  23. }
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