Two examples of PHP recursive deletion of directories (folders) are given below. One is the code to delete a single empty directory, and the other is the code to delete directory folders in batches.
php tutorial Recursively delete directories (folders) Two examples are given below, one is the code to delete a single empty directory, and the other is the code to delete directory folders in batches.
//Delete a single empty folder
$dir = 'www.bkjia.com';
if( is_dir( $dir ) ) // Determine whether it is a directory
{
if( rmdir( $dir ) )
{
echo 'Directory deleted successfully';
}
else
{
echo 'The directory was not deleted Permissions';
}
}
else
{
echo 'is not a valid directory';
}
//Let’s look at one Function to delete directories recursively in batches.
function deletedir($dir){
if(!handle=@opendir($dir)){ //Check whether the directory to be opened exists
die("There is no such directory"); deletedir($file);
U> if (@unlink ($ file)) {
echo "file & lt; b & gt; $ file & lt;/b & gt; delete success. ;b>$fileDelete failed!
";
ir)){
echo "Directory< ;b>$dirDeletion successful.
n";
}else{
";
}
}
//Test program
$dir="/var/www/test";
deletedir($dir);
http://www.bkjia.com/PHPjc/444866.html
www.bkjia.com
true