
PHP 遍历文件夹下的文件以及子文件夹
发布日期:2021-05-09 04:16:57
浏览次数:18
分类:博客文章
本文共 1151 字,大约阅读时间需要 3 分钟。
// 递归的方式实现
function my_dir( $dir ){ if ( !is_dir($dir) ) { return 'not dir';die(); } $files = array(); $dir_list = scandir($dir); foreach( $dir_list as $file ) { if( $file!='.' && $file!='..' ) { if( is_dir( $dir.'/'.$file )) { $files[$file] = my_dir( $dir.'/'.$file ); } else { $files[] = $file; } } } return $files;};
// 队列方式实现
function my_dir_list( $dir )
{ if( !is_dir( $dir) ) { return 'not dir';die(); } $files = array(); $queue = array( $dir ); // $data = each( $queue ); while( $data = each( $queue) ) { $path = $data['value']; $handle = opendir( $path ); if( is_dir($path) && $handle ) { // $file = readdir( $handle ); while( $file = readdir( $handle) ) { if ( $file == '.' || $file == '..' ) { continue; } else { $real_path = $path.'/'.$file; $files[] = $real_path; if( is_dir($real_path) ) { $queue[] = $real_path; } } } } closedir($handle); } return $files;}
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2025年04月07日 05时55分10秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
控制文件
2021-05-09
SMON进程、PMON进程、LGWR/ARCH
2021-05-09
Oracle text组件安装
2021-05-09
RAC环境修改参数生效测试
2021-05-09
Oracle 10g安装报错记录
2021-05-09
ConcurrentHashMap 源码分析
2021-05-09
在不影响程序使用的情况下添加shellcode
2021-05-09
isEmpty和isNull()区别
2021-05-09
刷LeetCode的简易姿势
2021-05-09