Home > php教程 > php手册 > php自定义函数之递归删除文件及目录

php自定义函数之递归删除文件及目录

WBOY
Release: 2016-06-06 20:34:52
Original
993 people have browsed it

自定义函数之递归删除文件及目录的php代码,需要的朋友可以参考下。

复制代码 代码如下:


/*—————————————————— */
//– 递归删除文件及目录
//– 例: del_dir (‘../cache/');注意:返回的/是必须的
//– $type 强制删除目录, true 是 ,false 否
/*—————————————————— */
function del_dir ($dir,$type=true)
{
$n=0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
//.svn 忽略 svn 版本控制信息
if ( $file == '.' or $file =='..' or $file == '.svn')
{
continue;
}
if (is_file ($dir.$file))
{
unlink($dir.$file);
$n++;
}
if (is_dir ($dir.$file))
{
del_dir ($dir.$file.'/');
if ($type)
{
$n++;
rmdir($dir.$file.'/');
}
}
}
}
closedir($dh);
}
return $n;
}

,香港空间,香港服务器,香港虚拟主机
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template