-
- function d_rmdir($dirname) { //Delete non-empty directory
- if(!is_dir($dirname)) {
- return false;
- } // bbs.it-home.org
- $handle = @opendir($dirname);
- while(($file = @readdir($handle)) !== false){
- if($file != '.' && $file != '..') {
- $dir = $dirname . '/' . $file;
- is_dir($dir) ? d_rmdir($dir) : unlink($dir);
- }
- }
- closedir($handle);
- return rmdir($ dirname) ;
- }
- if(d_rmdir("./temp"))
- echo "succes";
- else
- echo "false";
- ?>
Copy code
Method 2, found in the PHP manual of.
-
- //Delete non-empty directory
- functionremove_directory($dir){
- if($handle=opendir("$dir")){
- while(false!==($item= readdir($handle))){
- if($item!="."&&$item!=".."){
- if(is_dir("$dir/$item")){
- remove_directory("$dir /$item");
- }else{
- unlink("$dir/$item");
- echo"removing$dir/$item
";
- }
-
- }
- closedir($handle);
- rmdir($dir);
- echo "removing$dir
";
- }
- }
Copy code
Method 3,
-
- //Function provided by netizens to delete non-empty directories
- functionremoveDir($dirName)
- {
- if(!is_dir($dirName))
- {
- returnfalse;
- }
- $handle =@opendir($dirName);
- while(($file=@readdir($handle))!==false)
- {
- if($file!='.'&&$file!='..')
- {
- 〉 dirName);
- }
- ?>
-
-
- Copy code
-
-
|