• We are available for any Development work:
  • Email us at: programmer_heart@yahoo.com

Remove Directory which is not empty

Here is the function for delete the directory which have contents. you can try this.


function deleteDirectory($dir) {
if (!file_exists($dir)) return true;
if (!is_dir($dir)) return unlink($dir);
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
if (!deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) return false;
}
return rmdir($dir);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *

Press Enter to Search