note 66009 added to function.rmdir
| From: | brianleeholub at yahoo dot com | Date: | Fri, 12 May 2006 06:30:22 +0000 |
| Subject: | note 66009 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111155@lists.php.net to get a copy of this message | ||
this will only work in php5 (scandir).
feed this function the path to a directory (INCLUDE TRAILING /) and it'll clean it of all
contents (if it contains a directory with more stuff it'll dive down and clean that out). use
with care!
remove_directory('/path/to/crap/for/deletion/');
function remove_directory($dir) {
$dir_contents = scandir($dir);
foreach ($dir_contents as $item) {
if (is_dir($dir.$item) && $item != '.' && $item != '..') {
remove_directory($dir.$item.'/');
}
elseif (file_exists($dir.$item) && $item != '.' && $item !=
'..') {
unlink($dir.$item);
}
}
rmdir($dir);
}
----
Server IP: 216.194.113.175
Probable Submitter: 72.194.110.250
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit -- http://master.php.net/note/edit/66009
Del: integrated -- http://master.php.net/note/delete/66009/integrated
Del: useless -- http://master.php.net/note/delete/66009/useless
Del: bad code -- http://master.php.net/note/delete/66009/bad+code
Del: spam -- http://master.php.net/note/delete/66009/spam
Del: non-english -- http://master.php.net/note/delete/66009/non-english
Del: in docs -- http://master.php.net/note/delete/66009/in+docs
Del: other reasons-- http://master.php.net/note/delete/66009
Reject -- http://master.php.net/note/reject/66009
Search -- http://master.php.net/manage/user-notes.php