note 88723 deleted from function.rmdir by danbrown
| From: | danbrown@php.net | Date: | Thu, 12 Feb 2009 18:14:17 +0000 |
| Subject: | note 88723 deleted from function.rmdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150581@lists.php.net to get a copy of this message | ||
Note Submitter: zeke1 at ezekielvictor dot com
----
Improvement on elprez's rmdir_recurse function. This one will also delete the top-level $path
after deleting its contents:
<?php
function rmdir_recurse($path)
{
$path = rtrim($path, '/').'/';
$handle = opendir($path);
while(false !== ($file = readdir($handle)))
{
if($file != '.' and $file != '..' )
{
$fullpath = $path.$file;
if(is_dir($fullpath))
rmdir_recurse($fullpath);
else
unlink($fullpath);
}
}
closedir($handle);
rmdir($path);
}
?>