Home > Backend Development > PHP Tutorial > PHP traverse directory

PHP traverse directory

WBOY
Release: 2016-07-25 09:08:41
Original
774 people have browsed it
Traverse all directories and files in the specified directory
  1. function list_dir($dir){
  2. static $result = array();
  3. if(is_dir($dir)){
  4. $file_dir = scandir($dir);// List files and directories in the specified path
  5. foreach($file_dir as $file){
  6. if($file == '.'||$file == '..'){
  7. continue;
  8. }elseif(is_dir( $dir.$file)){
  9. list_dir($dir.$file.'/');
  10. }else{
  11. array_push($result,$dir.$file);//Data pushed onto the stack
  12. }
  13. }
  14. }
  15. return $result;
  16. }
  17. $arr = list_dir('E:/wwwroot/test/');
  18. print_r($arr);
  19. ?>
Copy code


Related labels:
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