Last active
August 29, 2015 14:02
-
-
Save juji/d5cfdc4f620f43e4dccf to your computer and use it in GitHub Desktop.
PHP - Delete directory content recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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