php递归删除目录与文件的方法
作者:php之路 时间:2023-09-12 02:02:02
本文实例讲述了php递归删除目录与文件的方法。分享给大家供大家参考。具体实现方法如下:
<?php
function deldir($path){
$dh = opendir($path);
var_dump(readdir($dh));
while(($d = readdir($dh)) !== false){
if($d == '.' || $d == '..'){//如果为.或..
continue;
}
$tmp = $path.'/'.$d;
if(!is_dir($tmp)){//如果为文件
unlink($tmp);
}else{//如果为目录
deldir($tmp);
}
}
closedir($dh);
rmdir($path);
}
$path = "./e";
deldir($path);
?>
希望本文所述对大家的PHP程序设计有所帮助。
标签:php,递归,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ASP正则获取图片地址
2009-09-03 13:18:00
JS遮罩层效果 兼容ie firefox jQuery遮罩层
2024-02-24 23:04:24
Tensorflow2.1实现文本中情感分类实现解析
2022-12-22 17:49:51
PHP实现将MySQL重复ID二维数组重组为三维数组的方法
2023-11-18 03:28:57
浅谈MySQL中的group by
2024-01-18 22:53:54
![](https://img.aspxhome.com/file/2023/1/102391_0s.jpg)
python颜色随机生成器的实例代码
2022-12-03 19:40:05
Mysql语法、特殊符号及正则表达式的使用详解
2024-01-12 21:56:50
源码编译安装MySQL8.0.20的详细教程
2024-01-22 11:55:52
![](https://img.aspxhome.com/file/2023/5/101355_0s.png)
python+excel接口自动化获取token并作为请求参数进行传参操作
2022-05-19 04:10:18
![](https://img.aspxhome.com/file/2023/0/96970_0s.jpg)
Python+Flask编写一个简单的行人检测API
2023-09-26 17:55:19
![](https://img.aspxhome.com/file/2023/5/85255_0s.png)
关于MySQL编码问题的经验总结
2007-08-23 16:10:00
python上传时包含boundary时的解决方法
2021-03-28 08:28:54
防止Access 2000密码被破译的方法
2008-11-20 16:48:00
离线安装Pyecharts的步骤以及依赖包流程
2021-12-16 11:43:12
![](https://img.aspxhome.com/file/2023/0/135170_0s.jpg)
Python enumerate函数功能与用法示例
2023-11-06 08:44:07
Python中关于面向对象私有属性方法的详细讲解
2022-11-29 05:38:36
![](https://img.aspxhome.com/file/2023/8/96988_0s.png)
MySQL表类型 存储引擎 的选择
2024-01-22 08:12:51
asp 使用正则表达式替换word中的标签,转为纯文本
2011-02-28 10:49:00
详解MySQL与Spring的自动提交(autocommit)
2024-01-26 15:19:02
基于webstorm卡顿问题的2种解决方法
2023-02-23 09:03:17
![](https://img.aspxhome.com/file/2023/2/132412_0s.jpg)