note 84377 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:21:11 +0000 |
| Subject: | note 84377 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153231@lists.php.net to get a copy of this message | ||
Note Submitter: kisgabo94 at freemail dot hu
----
A function that deletes a dir that not empty:
Returns true on success, or false on faileure.
<?php
function advancedRmdir($path) { //mappát töröl akkor is, ha nem üres
$origipath = $path;
$handler = opendir($path);
while (true) {
$item = readdir($handler);
if ($item == "." or $item == "..") {
continue;
} elseif (gettype($item) == "boolean") {
closedir($handler);
if (!@rmdir($path)) {
return false;
}
if ($path == $origipath) {
break;
}
$path = substr($path, 0, strrpos($path, "/"));
$handler = opendir($path);
} elseif (is_dir($path."/".$item)) {
closedir($handler);
$path = $path."/".$item;
$handler = opendir($path);
} else {
unlink($path."/".$item);
}
}
return true;
}
?>