删除无限级目录与文件代码共享
2006-07-12 00:00
495 查看
<?
//删除目录
//本程序由wm_chief原创,如要转载,请注明作者与来源(http://www.phome.net)
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"删除完毕";
}
//删除目录
//本程序由wm_chief原创,如要转载,请注明作者与来源(http://www.phome.net)
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清空(删除)指定目录下的文件,不删除目录文件夹的实现代码
- 删除目录下相同文件的python代码(逐级优化)
- Java 删除文件和目录代码
- PHP FTP操作类代码( 上传、拷贝、移动、删除文件/创建目录)
- 当web.config文件放置在共享目录下(UNC),启动IIS会提示有错误信息500.19,伴随有错误代码0x80070003和错误代码0x80070005的解决办法
- Hadoop程序中怎样用代码删除hafs中的文件和目录
- windows删除一个目录下的文件c代码
- 代码分类之删除文件、目录及目录下的所有文件
- PHP利用一行代码删除目录下所有文件方法示例
- 在服务端进行目录建立、删除,文件上传、删除的过程的php代码
- 用实现ASP批量删除目录及文件的代码
- 用实现ASP批量删除目录及文件的代码
- CMD下一个命令遍历目录并删除相同文件的代码
- Java 删除文件和目录代码