在我们日常开发工作中,经常会遇到遍历文件目录的情况,相信大家也知道对于遍历文件目录的有很多种,PHP本身也提供了很多有用的函数,如果目录很多,大家都会用队列方式,但是我们今天给大家介绍的是php遍历文件目录的类使用!
第一步:
下载我们本次需要使用的phpphp遍历文件目录的类:http://www.gaodaima.com/xiazai/leiku/823
第二步:
把下载的文件解压都本地,然后实例化类:
1.获取目录列表:
<?php$Dir_dir = './example';$getDirFile = new getDirFile();$getDir = $getDirFile->getDir( $Dir_dir );print_r($getDir);?>
结果:
2.获取文件列表
<?php$File_one_dir = './example/example_one';$File_two_dir = 'E:/Workspace/mycode/getDirFile/example/example_two';$getDirFile = new getDirFile();$getFile_one = $getDirFile->getFile( $File_one_dir );$getFile_two = $getDirFile-&g<b style="color:transparent">本文来源gao@!dai!ma.com搞$$代^@码!网!</b><strong>搞gaodaima代码</strong>t;getFile( $File_two_dir );print_r($getFile_one);print_r($getFile_two);?>
结果显示:
3.获取目录/文件列表
<?php$Dir_dir = './example';$getDirFile = new getDirFile();$getDirFile = $getDirFile->getDirFile( $Dir_dir );print_r($getDirFile);?>
结果显示:
以上就是php如何遍历文件目录的方法教程的详细内容,更多请关注搞代码gaodaima其它相关文章!