PHP Classes

rmdir Warning: file exists > NO IT DOES NOT!

Recommend this page to a friend!

      Top level forums  >  PHP Specialists  >  General  >  rmdir Warning: file exists > NO IT...  
Subject:rmdir Warning: file exists > NO IT...
Summary:When trying to delete a folder it says it is not empty,but IT IS
Author:Sander Korst
Date:2013-05-05 20:24:59
Update:2013-05-23 00:32:18

  1. rmdir Warning: file exists > NO IT...   Reply   Report abuse  
Sander Korst - 2013-05-06 01:59:43
Hi There,

I hope someone here can help me out with this crazy error.

The situation is as following:
In a script I create folder A. Then in this folder I place 2 .xls files, and 1 subfolder (folder B) that contains several images.

Then at the end of the script I run the following code to delete all files and subfolders (for the record, the script works, and I tried several other working script too. But to be sure):

function deleteDirectory($dir) {
if (!file_exists($dir)) return true;
if (!is_dir($dir)) return unlink($dir);
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
if (!deleteDirectory($dir.DIRECTORY_SEPARATOR.$item)) return false;
return rmdir($dir);

After this, I do the rmdir($folder_A) to remove it.

And then it happens: I get the error "Warning: file exists in Folder A" and it doesnt delete it.

But when I look in the folder via my ftp program, the folder is EMPTY (folder B is gone, and so are all the files) and 0 bytes. When I run another script which contains only the "rmdir($folder_A)" at this point, it removes the folder without any problems.

How is this possible? What happens?

I really really hope that someone has some genius idea of what this could be... Thanks a lot in advance!

PS: The folders A and B have the same rights (750) and they where within the same script.

There are 4 replies in this thread, which are not being displayed.
Browsing this forum thread replies is available only to premium subscribers.

Go to the premium subscriptions page to learn how to become a premium subscriber and have full access to this forum.