Home > Article > Backend Development > Delete all folders and subdirectories in a directory with PHP under Linux_PHP tutorial
[php]
function removeDir($dirName)
{
if(! is_dir($dirName))
{
@unlink($dirName);
return false;
}
$handle = @opendir($dirName);
while(($file = @readdir($handle)) !== false)
{
if($file != '.' && $file != '..')
{
$dir = $dirName . '/' . $file;
is_dir($dir) ? removeDir($dir) : @unlink($dir);
}
}
closedir($handle);
return rmdir($dirName) ;
}
$dirName1="bmz_cache";
removeDir($dirName1);
?>