Created
April 7, 2012 16:26
-
-
Save javierav/2330131 to your computer and use it in GitHub Desktop.
Script PHP para borrar de forma recursiva un directorio
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 | |
/* | |
* this function removes a directory and its contents. | |
* use with careful, no undo! | |
*/ | |
function rmdir_recursive($dir) { | |
$files = scandir($dir); | |
array_shift($files); // remove '.' from array | |
array_shift($files); // remove '..' from array | |
foreach ($files as $file) { | |
$file = $dir . '/' . $file; | |
if (is_dir($file)) { | |
rmdir_recursive($file); | |
rmdir($file); | |
} else { | |
unlink($file); | |
} | |
} | |
rmdir($dir); | |
} | |
// remove directory /home/nash/tmp | |
$dir = '/home/nash/tmp'; | |
rmdir_recursive($dir); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment