note 30876 added to function.rmdir
| From: | csnyder at mvpsoft dot com | Date: | Tue, 01 Apr 2003 21:16:14 +0000 |
| Subject: | note 30876 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46095@lists.php.net to get a copy of this message | ||
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);
}
}
--
http://www.php.net/manual/en/function.rmdir.php
http://master.php.net/manage/user-notes.php?action=edit+30876
http://master.php.net/manage/user-notes.php?action=delete+30876
http://master.php.net/manage/user-notes.php?action=reject+30876