Created
August 4, 2016 11:53
-
-
Save dewwwald/fb3059d2e5c21bf97dc2b5494d9e566e to your computer and use it in GitHub Desktop.
Recurse dirr deletion
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
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