Skip to content

Instantly share code, notes, and snippets.

@dewwwald
Created August 4, 2016 11:53
Show Gist options
  • Save dewwwald/fb3059d2e5c21bf97dc2b5494d9e566e to your computer and use it in GitHub Desktop.
Save dewwwald/fb3059d2e5c21bf97dc2b5494d9e566e to your computer and use it in GitHub Desktop.
Recurse dirr deletion
private function delete_dir($dirPath)
{
if (! is_dir($dirPath))
{
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/')
{
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file)
{
if (is_dir($file))
{
$this->deleteDir($file);
}
else
{
unlink($file);
}
}
rmdir($dirPath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment