php 刪除無限級目錄與文件代碼共享
更新時間:2008年11月22日 22:27:21 作者:
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"刪除完畢";
}
?>
//刪除目錄
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中require和require_once的區(qū)別說明
本篇文章主要是對php中require和require_once的區(qū)別進行了說明介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02
PHP使用PHPexcel導入導出數(shù)據(jù)的方法
這篇文章主要介紹了PHP使用PHPexcel導入導出數(shù)據(jù)的方法,以實例形式較為詳細的分析了PHP使用PHPexcel實現(xiàn)數(shù)據(jù)的導入與導出操作相關技巧,需要的朋友可以參考下2015-11-11

