Home > Backend Development > PHP Tutorial > PHP custom function to recursively delete files and directories_PHP tutorial

PHP custom function to recursively delete files and directories_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:35:03
Original
780 people have browsed it

Copy code The code is as follows:

/*—————————————————— * /
//– Recursively delete files and directories
//– Example: del_dir ('../cache/'); Note: the returned / is required
//– $type forces directory deletion , true yes, false no
/*———————————————————— */
function del_dir ($dir,$type=true)
{
$n=0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) ! == false) {
//.svn ignore svn version control information
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;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322314.htmlTechArticleCopy the code as follows: /*———————————————— — */ //– Recursively delete files and directories //– Example: del_dir ('../cache/'); Note: The returned / must be...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template