Native php recursively delete files + folders

Native php recursively delete files + folders

 <?php function deldir($dirname){   if(file_exists($dirname)) {//Determine whether there is a folder $dir=opendir($dirname);//Open the folder while($filename=readdir($dir)){//Read the 123 folder the data if($filename!="." && $filename!=".."){//remove.and..except $file=$dirname."/".$filename;           if(is_dir($file)){             deldir($file); //Use recursive deletion of subdirectories, that is to say, to determine whether there are folders in the 123 folder, if there is traversal and then delete}else{             echo 'Delete file<b>'.$file.'</b>success<br>';             unlink($file);           }       }   }   closedir($dir);   echo 'Delete directory<b>'.$dirname.'</b>success<br>';   rmdir($dirname);   } } deldir('D:\123');//For example, the file is in the 123 directory of the d drive?> 

The post Native php recursively delete files + folders first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/8748
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment