php如何实现递归遍历文件目录?
来源:互联网 发布:plsql打开sql文件乱码 编辑:程序博客网 时间:2024/06/05 06:19
/** * 文件列表类 */class dirListClass{ /** * 获取文件目录 * @param $dir 目录 */ public function getList($dir){ $list = $this->scandir_list($dir); $this->lists($list); } /** * 获取有深度的目录数组 * @param $dir * @return array|string */ private function scandir_list($dir){ $files = ''; if ($opendir = opendir($dir)) { while (($file = readdir($opendir)) !== false) { if ($file != '..' && $file != '.') { if (is_dir($dir . '/' . $file)) { $files[$file] = $this->scandir_list($dir . '/' . $file); $files['length'] = substr_count($dir . '/' . $file, '/'); } else { $files[] = $file; $files['length'] = substr_count($dir . '/' . $file, '/') - 1; } } } closedir($opendir); return $files; } } /** * 输出目录列表 * @param $list */ private function lists($list) { if (!empty($list)) {//print_r($list); $length = 0; foreach ($list as $key => $value) { if ($key == 'length') { $length = $value; continue; } if (isset($value['length'])) { $length = $value['length']; unset($value['length']); } if (gettype($key) == 'string') { for ($i = 0; $i < $length - 1; $i++) { echo '----'; } echo $key . "<br>"; $this->lists($list[$key]); } else { for ($i = 0; $i < $length; $i++) { echo '----'; } echo $value . "<br>"; } } } }}
0 0
- php如何实现递归遍历文件目录?
- php递归遍历文件目录
- php 递归遍历目录与文件
- php递归遍历目录下的文件
- php递归遍历目录下的文件
- PHP递归遍历目录,递归删除目录及文件
- PHP目录文件遍历实现
- PHP实现目录文件遍历
- php递归遍历目录
- php递归函数实现遍历指定文件下的目录与文件数量
- 递归遍历目录文件
- 递归遍历目录文件
- php递归方式遍历目录
- php遍历文件目录
- 递归遍历Linux下的目录文件源码实现
- PHP实现目录遍历
- 递归与非递归 遍历文件目录
- 递归与非递归遍历文件目录
- Ubuntu16.04 QT "QMYSQL driver not loaded on Ubuntu"问题
- Ubuntu14.04不能全屏显示的解决办法
- 2017.4.26 补天挖洞
- Ubuntu 16.04 安装mysql并设置远程访问
- Caffe学习:pycaffe接口配置
- php如何实现递归遍历文件目录?
- 常见的中间件有哪些?
- 521. Longest Uncommon Subsequence I
- 读书笔记《Effective C++》条款06:若不想使用编译器自动生成的函数,就该明确拒绝
- 【微信小程序源码案例】小程序项目开发案例经验分享
- 意象与文化符号、哲学范畴
- CentOS 6.3虚拟机网络环境配置
- c++第五次实验
- 极简的dp代码