Created
March 29, 2013 22:13
-
-
Save paulund/5274044 to your computer and use it in GitHub Desktop.
Delete a directory and all files in the directory with PHP.
This file contains hidden or 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 delete_directory($dirname) { | |
if (is_dir($dirname)) | |
$dir_handle = opendir($dirname); | |
if (!$dir_handle) | |
return false; | |
while($file = readdir($dir_handle)) { | |
if ($file != "." && $file != "..") { | |
if (!is_dir($dirname."/".$file)) | |
unlink($dirname."/".$file); | |
else | |
delete_directory($dirname.'/'.$file); | |
} | |
} | |
closedir($dir_handle); | |
rmdir($dirname); | |
return true; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment