首页 > 资讯列表 > 编程/数据库 >> PHP

php 删除无限级目录与文件代码

PHP 2014-12-13 08:57:04 转载来源: 网络整理/侵权必删

本文是一个php实现的可以用来 删除无限级目录与文件的代码示例,感兴趣的同学参考下. php下需要删除多级目录的朋友及可以参考下面的类 <? //删除目录 class del_path { function wm_chief_delpath($del_path) { if(!file_exists($del_path))//目标目录不存在则建立 {echo"目录不存在";return false;} $hand=opendir($del_path); $i=0; while($file=readdir($hand)) {$i ; if($i==1||$i==2) {continue;} if(!(strchr($file,"

本文是一个php实现的可以用来 删除无限目录文件代码示例,感兴趣的同学参考下.

php下需要删除多级目录的朋友及可以参考下面的类
<?
//删除目录
class del_path
{
function wm_chief_delpath($del_path)
{
if(!file_exists($del_path))//目标目录不存在则建立
{echo"目录不存在";return false;}
$hand=opendir($del_path);
$i=0;
while($file=readdir($hand))
{$i ;
if($i==1||$i==2)
{continue;}
if(!(strchr($file,".")))
{
$del_s_path=$del_path."/".$file;
$this->wm_chief_delpath($del_s_path);
}
else
{
$del_file=$del_path."/".$file;
$this->wm_chief_file($del_file);
}
}
closedir($hand);
$this->wm_chief_path($del_path);
return true;
}
//删除文件
function wm_chief_file($del_file)
{
unlink($del_file);
}
//删除目录
function wm_chief_path($del_path)
{
rmdir($del_path);
}
}
$DelPath="DelPath";//要删除的目录
$wm_chief=new del_path();
$wm_chief_ok=$wm_chief->wm_chief_delpath($DelPath);
if($wm_chief_ok)
{
echo"删除完毕";
}
?>


标签: php 删除 无限 目录 文件 代码


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持