php 删除无限级目录与文件代码的简单示例

对php删除无限级目录与文件代码共享感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!

/**
 * php删除无限级目录与文件代码共享
 *
 * @param 
 * @arrange 512-笔记网: www.jb51.cc
 **/
//删除目录
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删除完毕;
}
/***   来自编程之家 jb51.cc(jb51.cc)   ***/

相关文章

文章浏览阅读8.4k次,点赞8次,收藏7次。SourceCodester Onl...
文章浏览阅读3.4k次,点赞46次,收藏51次。本文为大家介绍在...
文章浏览阅读1.1k次。- php是最优秀, 最原生的模板语言, 替代...
文章浏览阅读1.1k次,点赞18次,收藏15次。整理K8s网络相关笔...
文章浏览阅读1.2k次,点赞22次,收藏19次。此网络模型提供了...
文章浏览阅读1.1k次,点赞14次,收藏19次。当我们谈论网络安...