DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
PHP Function To Delete A Non Empty Directory
// PHP Function to delete a non empty directory
function deleteDir($dir)
{
if ($handle = opendir($dir))
{
$array = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($dir.$file))
{
if(!@rmdir($dir.$file)) // Empty directory? Remove it
{
//deleteDir($dir.$file.'/'); // Not empty? Delete the files inside it
}
}
else
{
@unlink($dir.$file);
}
}
}
closedir($handle);
@rmdir($dir);
}





