php 遍历目录下的所以文件和文件夹
2016-07-15 16:15
661 查看
<?php /** * 遍历文件夹和文件列 * @author lizhiming * @date 2016/06/30 */ define('DS', DIRECTORY_SEPARATOR); class File { //返回数组 private $DirArray = array(); private $FileArray = array(); private $DirFileArray = array(); private $Handle, $Dir, $File; //获取目录列表 public static function getDir(& $Dir) { if (is_dir($Dir)) { if (false != ($Handle = opendir($Dir))) { while (false != ($File = readdir($Handle))) { if ($File != '.' && $File != '..' && !strpos($File, '.') && is_dir($File)) { $DirArray[] = $File; } } closedir($Handle); } } else { $DirArray[] = '[Path]:\'' . $Dir . '\' is not a dir or not found!'; } return $DirArray; } //获取文件列表 public static function getFile(& $Dir) { if (is_dir($Dir)) { if (false != ($Handle = opendir($Dir))) { while (false != ($File = readdir($Handle))) { if (($File != '.' && $File != '..' && strpos($File, '.')) || is_file($File)) { $FileArray[] = $File; } } closedir($Handle); } } else { $FileArray[] = '[Path]:\'' . $Dir . '\' is not a dir or not found!'; } return $FileArray; } //获取目录/文件列表 public static function getDirFile(& $Dir) { if (is_dir($Dir)) { $DirFileArray['DirList'] = self::getDir($Dir); if ($DirFileArray) { foreach ($DirFileArray['DirList'] as $Handle) { $File = $Dir . DS . $Handle; $DirFileArray['FileList'][$Handle] = self::getFile($File); } } } else { $DirFileArray[] = '[Path]:\'' . $Dir . '\' is not a dir or not found!'; } return $DirFileArray; } }
相关文章推荐
- [置顶] ThinkPHP单字母函数总结
- thinkphp——显示当前时间与计算时间差
- Yii编程开发常见调用技巧集锦
- php5.4压缩包版(zip)安装教程
- php 自定义扩展
- 架设自己的FTP服务器 Serv-U详细配置图文教程
- 利用虚拟机搭建FTP服务
- OrCAD:添加footprint属性图文教程
- FragmentPagerAdapter中的fragment类型问题
- php 根据某数组key计算和
- Yii列表定义与使用分页方法小结(3种方法)
- Yii 简介
- Yii模型操作之criteria查找数据库的方法
- 友好的显示时间 PHP端
- php webservice 可能存在的坑
- PHP静态变量和全局变量的区别
- 搞不清FastCgi与PHP-fpm之间是个什么样的关系
- ATOM基础教程一atom-autocomplete-php配置(14)
- sublime 直接运行php代码
- 【框架】JitPack---如何拥有自己的动态库