Skip to content

Instantly share code, notes, and snippets.

@ch-gilbert
Created January 15, 2014 02:46
Show Gist options
  • Select an option

  • Save ch-gilbert/8429910 to your computer and use it in GitHub Desktop.

Select an option

Save ch-gilbert/8429910 to your computer and use it in GitHub Desktop.
recursively delete a directory
function rmdir_r($dir) {
if (!is_dir($dir)) {
return false;
}
$files = scandir($dir);
foreach ($files as $file) {
if ($file === '.' || $file === '..') {
continue;
}
$file = $dir . DIRECTORY_SEPARATOR . $file;
if (is_dir($file)) {
rmdir_r($file);
rmdir($file);
} else if (is_file($file)) {
unlink($file);
}
}
return true;
}
//rmdir_r('assets');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment