Skip to content

Instantly share code, notes, and snippets.

@julienhay
Last active January 2, 2016 16:59
Show Gist options
  • Save julienhay/8333892 to your computer and use it in GitHub Desktop.
Save julienhay/8333892 to your computer and use it in GitHub Desktop.
Delete directory PHP function
<?php
function deleteDirectory($dirname, $delete_self = true)
{
$dirname = rtrim($dirname, '/').'/';
if ($files = scandir($dirname))
{
foreach ($files as $file)
if ($file != '.' && $file != '..' && $file != '.svn')
{
if (is_dir($dirname.$file))
Tools::deleteDirectory($dirname.$file, true);
elseif (file_exists($dirname.$file))
unlink($dirname.$file);
}
if ($delete_self)
rmdir($dirname);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment