php 删除无限级目录与文件代码共享
2008-11-22 00:00
766 查看
<?
//删除目录
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"删除完毕";
}
?>
//删除目录
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代码搞定删除文件、删除目录
- php 删除目录下N分钟前创建的所有文件的实现代码
- PHP unlink与rmdir删除目录及目录下所有文件实例代码
- php清空(删除)指定目录下的文件,不删除目录文件夹的实现代码
- PHP利用一行代码删除目录下所有文件方法示例
- PHP FTP操作类代码( 上传、拷贝、移动、删除文件/创建目录)
- PHP删除目录和目录内所有的下级目录、文件代码
- PHP FTP操作类代码( 上传、拷贝、移动、删除文件/创建目录)
- PHP 删除一个目录及目录下的所有文件的函数代码
- 在服务端进行目录建立、删除,文件上传、删除的过程的php代码
- php清空(删除)指定目录下的文件,不删除目录文件夹的实现代码
- php 删除目录下N分钟前创建的所有文件的实现代码