php源码之遍历目录下的所有的文件

<?php
//遍历目录下的所有的文件 -- 递归调用
// http://www.manongjc.com/article/1495.html
function get_all_file1($path){
    if($path != '.' && $path != '..' && is_dir($path)){     //判断是否是目录,并且不是. 和..
        $files = [];                                        //存储文件信息
        if($handle = opendir($path)){                       //打开
            while($file = readdir($handle)){                //读取
                if($file != '.' && $file != '..'){
                    $file_name = ($path . DIRECTORY_SEPARATOR . $file);
                    if(is_dir($file_name)){                 //判断是否是目录
                        $files[$file] = get_all_file1($file_name);      //递归
                    }else{
                        $files[] = $file_name;
                    }
                }
            }
        }
    }
    closedir($handle);                                          //关闭句柄
    return $files;
}
// http://www.manongjc.com/article/1481.html
var_dump(get_all_file1('F:Apachewww	empphp_demo'));
?>
原文地址:https://www.cnblogs.com/myhomepages/p/5987721.html