Take a look at the code first
Copy the code The code is as follows:
function deldir($dir) {
//Delete the files in the directory first:
$dh=opendir($dir);
while ($file=readdir($dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) {
unlink($fullpath);
} else {
deldir($fullpath);
}
}
}
closedir($dh);
//Delete the current folder:
if( rmdir($dir)) {
return true;
} else {
return false;
}
}
?>
unlink( ) function is used to delete files. Returns true if successful, false if failed. The rmdir() function is used to delete empty directories. It attempts to delete the directory specified by dir. The directory must be empty and must have appropriate permissions.
An example: delete all ".svn" folders under a certain folder (including their contents).
Copy code The code is as follows:
function delsvn($dir) {
$ dh=opendir($dir);
//Find all ".svn" folders:
while ($file=readdir($dh)) {
if($file!=". " && $file!="..") {
$fullpath=$dir."/".$file;
if(is_dir($fullpath)) {
if($file==" .svn"){
delsvndir($fullpath);
}else{
delsvn($fullpath);
}
}
}
}
closedir( $dh);
}
function delsvndir($svndir){
//Delete the files in the directory first:
$dh=opendir($svndir);
while($file= readdir($dh)){
if($file!="."&&$file!=".."){
$fullpath=$svndir."/".$file;
if (is_dir($fullpath)){
delsvndir($fullpath);
}else{
unlink($fullpath);
}
}
}
closedir($ dh);
//Delete directory folder
if(rmdir($svndir)){
return true;
}else{
return false;
}
}
$dir=dirname(__FILE__);
//echo $dir;
delsvn($dir);
?>
http://www.bkjia.com/PHPjc/323984.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323984.htmlTechArticleLook at the code first. Copy the code as follows: ? function deldir($dir) { //Delete the directory first File: $dh=opendir($dir); while ($file=readdir($dh)) { if($file!="." $file!="..") {...