用php自定义函数之递归删除文件及目录
自定义函数之递归删除文件及目录的php代码,需要的朋友可以参考下。希望对大家有所帮助!
代码如下:
/*—————————————————— */
/pic/p>
/pic/cache/');注意:返回的/是必须的
/pic/p>
/*—————————————————— */
function del_dir ($dir,$type=true)
{
$n=0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
/pic/p>
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;
}
【用php自定义函数之递归删除文件及目录】相关文章:
php递归遍历删除文件的方法11-05
php递归创建和删除文件夹的代码01-20
用PHP遍历目录下的全部文件03-17
PHP文件与目录操作的方法10-02
PHP分页自定义函数11-20
php递归函数三种方式02-21
php文件操作函数解释02-09
PHP常用的文件操作函数11-28
PHP遍历目录文件常用方法03-06