note 98622 modified in function.rmdir by danbrown
| From: | danbrown@php.net | Date: | Sat, 26 Jun 2010 23:59:16 +0000 |
| Subject: | note 98622 modified in function.rmdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170501@lists.php.net to get a copy of this message | ||
Another simple way to recursively delete a directory that is not empty:
<?php
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir")
rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
?>
--was--
Another simple way to recursively delete a directory that is not empty:
<?php
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") {
rrmdir($dir."/".$object);
rmdir($dir."/".$object);
} else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
?>
http://php.net/manual/en/function.rmdir.php