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

yipeiwu_com6年前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日历[测试通过]

比较不错的一款php日历代码复制代码 代码如下:<?php /** * 日历 * * Copyright(c) 2007 by 陈毅鑫(深空). All rights reserv...

php网页后退不再出现过期

<?php  ob_start();  if(function_exists(session_cache_limiter)) { sessi...

php smarty 二级分类代码和模版循环例子

php smarty 二级分类代码和模版循环例子

二级分类的数据表结构如下: PHP代码如下 复制代码 代码如下: /** @ 文章分类 含二级分类 @ param int $rootnum -- 一级分类数量 @ param int...

php从数据库查询结果生成树形列表的方法

本文实例讲述了php从数据库查询结果生成树形列表的方法。分享给大家供大家参考。具体分析如下: 本代码可以从数据库读取数据生成一个类似于windows的资源管理器的树形列表 <&...

php+ajax实现仿百度查询下拉内容功能示例

php+ajax实现仿百度查询下拉内容功能示例

本文实例讲述了php+ajax实现仿百度查询下拉内容功能。分享给大家供大家参考,具体如下: 运行效果如下: html代码: <!DOCTYPE html> <ht...