1

I'm using rmdir() within PHP on Windows to recursively delete a folder structure. It deletes all the contents of the folder fine, but leaves the base folder in an "unaccessible" state. I still have to delete that folder manually, even though the system says it can't be found. Somehow the act of "deleting" reminds the OS that it needs to actually remove it.

Here's my code with sources commented in:

function rrmdir($dir)
{
    // Taken from:
    // https://stackoverflow.com/a/3338133/6674014
    if(is_dir($dir))
    {
        $objects = scandir($dir);
        foreach($objects as $object)
        {
            if($object != "." && $object != "..")
            {
                if(is_dir($dir."/".$object))
                    $this->rrmdir($dir."/".$object);
                else
                {
                    // Added modification from comment attached to:
                    // https://stackoverflow.com/a/12148318/6674014
                    $objPath = $dir.'/'.$object;
                    chmod($objPath, 999);
                    unlink($objPath);
                }
            }
        }

        rmdir($dir);
    }
}

I've also used the $handle method, as well as the Folder Iterator Thing. These have also not worked.

And here's the error when I double-click the ghost folder:

How can this problem be fixed? Is it my code or OS that's messing up?

DCOPTimDowd
  • 231
  • 1
  • 11

0 Answers0