Skip to content

Instantly share code, notes, and snippets.

@juji
Last active August 29, 2015 14:02
Show Gist options
  • Save juji/d5cfdc4f620f43e4dccf to your computer and use it in GitHub Desktop.
Save juji/d5cfdc4f620f43e4dccf to your computer and use it in GitHub Desktop.
PHP - Delete directory content recursively
function delRec($dirPath){
foreach(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$dirPath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
$path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());
}
//uncomment to delete $dirPath
//rmdir($dirPath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment