note 81997 added to function.rmdir
| From: | rjcarr at gmail dot com | Date: | Sun, 23 Mar 2008 07:08:52 +0000 |
| Subject: | note 81997 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137343@lists.php.net to get a copy of this message | ||
To the poster on 03-Mar-2008 05:33, if the directory contains more than one file, your rmdir($f)
will (silently) warn that the dir isn't empty.
I think the following, although not quite as elegant, fixes the problem.
<?php
function deltree($f) {
if (is_dir($f)) {
foreach(glob($f.'/*') as $sf) {
if (is_dir($sf) && !is_link($sf)) {
deltree($sf);
rmdir($sf);
} else {
unlink($sf);
}
}
}
rmdir($f);
}
?>
----
Server IP: 208.69.120.35
Probable Submitter: 71.112.214.5
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit -- https://master.php.net/note/edit/81997
Del: integrated -- https://master.php.net/note/delete/81997/integrated
Del: useless -- https://master.php.net/note/delete/81997/useless
Del: bad code -- https://master.php.net/note/delete/81997/bad+code
Del: spam -- https://master.php.net/note/delete/81997/spam
Del: non-english -- https://master.php.net/note/delete/81997/non-english
Del: in docs -- https://master.php.net/note/delete/81997/in+docs
Del: other reasons-- https://master.php.net/note/delete/81997
Reject -- https://master.php.net/note/reject/81997
Search -- https://master.php.net/manage/user-notes.php