note 30876 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Sun, 05 Sep 2004 07:14:50 +0000 |
| Subject: | note 30876 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76028@lists.php.net to get a copy of this message | ||
Note Submitter: csnyder at mvpsoft dot com
----
I modified the delete_all_from_dir function above to have it fit in with the coding style for my
project, as well as making it work better (it didn't work before if the directory did not end
with a /) and making it delete the actual directory (before it just deleted the contents). Here it
is:
function recursiveDelete($dir)
{
if ($handle = @opendir($dir))
{
while (($file = readdir($handle)) !== false)
{
if (($file == ".") || ($file == ".."))
{
continue;
}
if (is_dir($dir . '/' . $file))
{
// call self for this directory
recursiveDelete($dir . '/' . $file);
}
else
{
unlink($dir . '/' . $file); // remove this file
}
}
@closedir($handle);
rmdir ($dir);
}
}