note 81692 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:21:51 +0000 |
| Subject: | note 81692 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153236@lists.php.net to get a copy of this message | ||
Note Submitter: dan
----
I use the following to delete a folder and all its content, and it works fine without being forced
to upgrade to PHP5:
function remove_dir($dir)
{
if(is_dir($dir))
{
$dir = (substr($dir, -1) != "/")? $dir."/":$dir;
$openDir = opendir($dir);
while($file = readdir($openDir))
{
if(!in_array($file, array(".", "..")))
{
if(!is_dir($dir.$file))
@unlink($dir.$file);
else
remove_dir($dir.$file);
}
}
closedir($openDir);
@rmdir($dir);
}
}