Home >Backend Development >PHP Tutorial >php traverses a directory and all files under it

php traverses a directory and all files under it

WBOY
WBOYOriginal
2016-07-25 08:54:28988browse
  1. function my_scandir($dir){
  2. $files=array();
  3. if(is_dir($dir)){
  4. if($handle=opendir($dir)){
  5. while(($file=readdir($handle))!==false){
  6. if($file!='.' && $file!=".."){
  7. if(is_dir($dir."/".$file)){
  8. $files[$file]=my_scandir($dir."/".$file);
  9. }else{
  10. $files[]=$dir."/".$file;
  11. }
  12. } // bbs.it-home.org
  13. }
  14. }
  15. }
  16. closedir($handle);
  17. return $files;
  18. }
复制代码


Statement:
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