Skip to content

Instantly share code, notes, and snippets.

@SteelPangolin
Created November 30, 2011 00:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteelPangolin/1407308 to your computer and use it in GitHub Desktop.
Save SteelPangolin/1407308 to your computer and use it in GitHub Desktop.
shutil.rmtree for PHP
<?php
/**
* Delete a file or directory recursively.
* @param string $path
*/
function rmtree($path)
{
if (is_dir($path))
{
foreach (scandir($path) as $name)
{
if (in_array($name, array('.', '..')))
{
continue;
}
$subpath = $path.DIRECTORY_SEPARATOR.$name;
rmtree($subpath);
}
rmdir($path);
}
else
{
unlink($path);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment