设为首页 加入收藏

TOP

php源码之遍历目录下的所有的文件
2017-10-10 12:00:25 】 浏览:7415
Tags: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:\Apache\www\temp\php_demo'));
?>

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇php rmdir使用递归函数删除非空目.. 下一篇php删除目录下的所有文件和目录

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目