php一个递归读取目录文件脚本
2012-11-14 13:13
543 查看
这个脚本写的非常好,值得参考。
读取截图:
注意,opendir不能打开远程目录,即以http://开头的目录,即使是本地的http也不行。
opendir("http://localhost/php"); 也会报错: failed to open dir: not implemented 这是这个问题
<?php function recurdir($thedir) { //first attempt to open the directory try{ if($adir=opendir($thedir)) { //scan through the directory while(false!==($anitem=readdir($adir))) { //do not count the . or .. in the directory if($anitem!='.'&&$anitem!='..') { //now ,if it is another directory,then you indent a bit //and go recursive if(is_dir($thedir.'/'.$anitem)) { ?> <span style="font-weight:bold;"><?php echo $anitem;?></span> <div style="margin-left:20px;"><?php recurdir($thedir.'/'.$anitem);?> </div> <?php } else if(is_file($thedir.'/'.$anitem)) { echo $anitem.'<br/>'; } } } }else { throw new Exception("Sorry,directory could not be opened"); } }catch(Exception $e){ echo $e->getmessage(); } } //recurdir("../google/zhanguo/demo2/"); recurdir('.'); ?>
读取截图:
注意,opendir不能打开远程目录,即以http://开头的目录,即使是本地的http也不行。
opendir("http://localhost/php"); 也会报错: failed to open dir: not implemented 这是这个问题
相关文章推荐
- PHP递归读取一个路径下的目录及文件
- 【php】读取"文件列表"按时间倒序显示,并递归显示各层目录、!
- 一个用递归遍历目录文件的脚本
- shell读取脚本同一个目录下的xml格式的文件
- PHP递归获取目录内所有文件的实现方法
- python 读取一个目录下的所有目录和文件
- Perl脚本递归替换所有指定目录指定文件类型中的指定模式
- Python读取一个目录下的目录及文件数
- Perl 脚本在给定的文件夹目录中递归查找文件
- php获取目录下所有文件路径(递归)
- C#读取一个目录,然后点击其中一个节点动态加载他的子目录和文件,节省开销
- Shell 递归多个子目录下的文件cp or mv到同一个目录下
- 读取指定目录下文件-- ---LIST+递归。(跳出结构思想。利用数据结构思路+程序写出更简单的逻辑。)
- php读取目录所有文件信息dir示例
- 创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来
- 脚本指令《游戏脚本的设计与开发》-第一章 读取和解析一个脚本文件
- 递归读取目录及删除文件
- php读取目录所有文件信息dir示例
- golang遍历某个目录下的文件,并读取文件名到一个csv文件
- php读取指定目录文件夹下所有文件夹及文件的方法