欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  类库下载

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

程序员文章站 2022-03-06 16:46:57
...
php源码之遍历目录下的所有的文件:
<!--?php
//遍历目录下的所有的文件 -- 递归调用
// <a rel="nofollow" href=" 
 target="_blank"-->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;
}
// <a rel="nofollow" href="http://www.manongjc.com/article/1481.html" 
target="_blank">http://www.manongjc.com/article/1481.html</a>
var_dump(get_all_file1('F:\Apache\www\temp\php_demo'));
?>

以上就是php源码之遍历目录下的所有的文件的内容,更多相关内容请关注PHP中文网(www.php.cn)!

相关标签: php,遍历目录