Last active
January 2, 2016 16:59
-
-
Save julienhay/8333892 to your computer and use it in GitHub Desktop.
Delete directory PHP function
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
<?php | |
function deleteDirectory($dirname, $delete_self = true) | |
{ | |
$dirname = rtrim($dirname, '/').'/'; | |
if ($files = scandir($dirname)) | |
{ | |
foreach ($files as $file) | |
if ($file != '.' && $file != '..' && $file != '.svn') | |
{ | |
if (is_dir($dirname.$file)) | |
Tools::deleteDirectory($dirname.$file, true); | |
elseif (file_exists($dirname.$file)) | |
unlink($dirname.$file); | |
} | |
if ($delete_self) | |
rmdir($dirname); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment