PHP遍历文件目录笔记
2009-12-30 15:36
190 查看
找到之前的一篇笔记,关于PHP遍历目录类。发布出来,加深印象
一位牛人说,优秀的代码不需要注释!言外之意是说不用注释,阅读者就能很好的理解!笔者没有达到这个水平,还是稍稍注释,其实用到的都是最基本的目录函数。
1: /**
2: * Open Read Write Close Dir and File
3: *
4: * @author Yaron [xyaron@gmail.com,http://yaron.org.cn]
5: * @version 0.1
6: * @package
7: */
8:
9: class fileDirOpt {
10: var $dirPath;
11: function openDir($dirPath){
12: $this->dirPath = $dirPath;
13: if (is_dir($dirPath)){
14: $dir = opendir($dirPath);
15: return $dir;
16: }else{
17: die("$dirPath is Not a Directory");
18: }
19: }
20: function closeDir($dir) {
21: closedir($dir);
22: }
23: function listDir($dir){
24: echo '';
25: while($file = readdir($dir)){
26: if($file!='.' && $file!='..'){ // filter . and ..
27: $dd = $this->dirPath; //
28: $dd = $dd.'/'.$file;
29: echo "$file ";
30: }
31: if(is_dir($dd) && $file!='.' && $file!='..') { // is_dir 参数需要完整的路径
32: $subDir = $this->openDir($dd);
33: $this->listDir($subDir);
34: $this->closeDir($subDir);
35: }
36: }
37: echo '';
38: return true;
39: }
40: }
41:
42: $dirOpt = new fileDirOpt();
43: $dirOpt->dirPath = 'd:/xampp';
44: $dir = $dirOpt->openDir($dirOpt->dirPath);
45: $dirOpt->listDir($dir);
46: $dirOpt->closeDir($dir);
一位牛人说,优秀的代码不需要注释!言外之意是说不用注释,阅读者就能很好的理解!笔者没有达到这个水平,还是稍稍注释,其实用到的都是最基本的目录函数。
相关文章推荐
- php实现遍历目录并删除指定文件中指定内容
- php洗牌代码和遍历文件目录代码
- PHP基础->文件读写->遍历目录->文件属性->建立、删除文件目录
- 遍历目录将目录中以.php为后缀名的文件改为.txt
- PHP遍历目录和文件列表
- php glob实现目录文件遍历与寻找与模式匹配的文件路径
- PHP遍历文件目录与清除目录中的文件
- php 遍历目录,生成目录下每个文件的md5值并写入到结果文件中
- php源码之遍历目录下的所有的文件
- php遍历替换目录下文件指定内容的方法
- 用命令行操作遍历目录,查找文件的PHP代码
- PHP文件操作:遍历文件目录
- PHP目录以及文件遍历类欢迎大家拍砖
- php高效遍历目录文件及子目录
- php glob()函数实现目录文件遍历与寻找与模式匹配的文件路径
- 目录下文件遍历及txt内容获取学习笔记
- php遍历统计文件目录和文件
- PHP遍历目录下全部文件
- php 遍历目录下的所以文件和文件夹
- Java精选笔记_IO流【File(文件)类、遍历目录下的文件、删除文件及目录】