Copy code The code is as follows:
function deldir($dir) {
//Delete the directory first Files under:
$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;
}
}
?>
Example: Delete a folder All ".svn" folders (including their contents are also deleted).
Copy the code The code is as follows:
< ;?php
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/326541.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326541.htmlTechArticleCopy the code as follows: ? function deldir($dir) { //Delete the files in the directory first: $dh =opendir($dir); while ($file=readdir($dh)) { if($file!="." $file!="..") { $fullpath=$dir."/...
Statement: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