views:

307

answers:

1

In my apps (VB6 and C# 2008) on Windows 2003 twice now I have seen similar behavior regarding deletion of folders containing files. My code will build some temp folder and generate files in that folder for subsequent processing. Upon processing completion, my code will try to delete the generated temp folder. The delete operation completes without error. However, upon further inspection, you can see that the folder still exists in windows explorer. Attempting to browse this folder results in a permission denied error. Later on the app will process another round of files and try to create the temp folder again. Unfortunately, the previous Pending Delete has not finished so trying to create the folder again results in permission denied error. The folder is not truly deleted until i close my app. As soon as the app is closed the folder gets deleted. Why are my folder delete operations not committed until the app is closed?

thanks!

+1  A: 

I wonder - is it possible you have accidentally retained a lock on that directory? that would explain why the directory cannot be removed until your app has departed.

There are some tools - try SysInternals - which will list file/directory locks. Try your app and then see if it retains a lock. I think you can then forcefully remove that lock - see then if the directory immediately disappears.

Blank Xavier
One additional question. Shouldn't deleting a folder with files actively locked files raise an exception rather than queuing a delete operation?