Skip to content

Instantly share code, notes, and snippets.

@ofca-snippets
Created September 15, 2012 23:11
Show Gist options
  • Save ofca-snippets/3730286 to your computer and use it in GitHub Desktop.
Save ofca-snippets/3730286 to your computer and use it in GitHub Desktop.
[php] Remove directory and all its children
function remove_directory($path)
{
$path = rtrim($path, '/').'/';
foreach (scandir($path) as $item)
{
if ($item == '.' OR $item == '..')
{
continue;
}
if (is_file($path.$item))
{
unlink($path.$item);
}
elseif (is_dir($path.$item))
{
remove_directory($path.$item.'/');
}
}
rmdir($path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment