PHP遍历文件夹内容
2015-08-17 10:19
579 查看
遍历文件,没什么技术含量,看了手册,还有事例代码,稍微修改一下,把文件夹下面的文件夹继续变量就OK了。 function listDir($dir){ //判断是否是文件夹 if(is_dir($dir)){ // 打开文件夹 if ($dh = opendir($dir)) { //读取文件夹 while (($file = readdir($dh)) !== false) { //如果文件夹中还有文件夹就继续遍历 //把 .和..排除 if(is_dir($dir.'/'.$file) && $file != '.' && $file != '..'){ echo '<hr>'."文件夹: $file ". "<br>"; //继续遍历 listDir($dir."/".$file."/"); }else{ //输出文件夹里面的内容 if($file != '.' && $file != '..') echo $file.'<br>'; } } closedir($dh); } } } listDir("D:\soft");
删除一个文件夹目录
function deldir($dir) { $dh=opendir($dir); while ($file=readdir($dh)) { if($file!="." && $file!="..") { $fullpath=$dir."/".$file; if(!is_dir($fullpath)) { unlink($fullpath); } else { deldir($fullpath); } } } closedir($dh); if(rmdir($dir)) { return true; } else { return false; } }
相关文章推荐
- 搭建匿名FTP
- thinkphp 分页
- PHP文件上传
- PHP中的加强型接口Traits
- PHP接口的思考
- php中的多态
- sPHP 之 XDebug
- PHP中的__call和__callStatic方法
- PHP中的__set和__get方法
- PHP中对象的本质
- php漂亮的分页类
- php 防止POST重复提交最简单方法
- phpStorm快捷键
- php-文件路径问题
- PHP 扩展开发[从零开始编写第一个PHP扩展]
- php中switch语句用法详解
- PHP给图片添加水印 压缩 剪切的封装类
- PHP:6种GET和POST请求发送方法
- Brainfuck Compiler on PHP
- thinkphp缓存应用