The code
Here's a grossly simplified pseudo-code version of some C# code that I'm debugging.
// 1) Lots of files and directories are copied
// 2) Some unnecessary files are deleted
// 3) Try to delete an unnecessary directory
string stubbornFolder = @"C:\...\Stubborn"; // This folder was created during step 1 above.
Directory.Delete(stubbornFolder);
The problem
When it hits Directory.Delete, the following exception is thrown.
System.IO.IOException: Access to the path 'C:\...\Stubborn' is denied.
Notes
Deleting the directory "C:...\test" also works as expected. test and Stubborn both appear to have the same security settings. Both directories are completely empty.
If I manually delete then re-create Stubborn using Windows Explorer (and skip over the copying code using a debugger), the deletion works as expected.
- Manual deletion works even when done while the application is running.
Peeking at the access control types like suggested in this question seemed to indicate that all rules were set to Allow.
The unnecessary file deletion works as expected.
Running the executable as an admin vs. not as an admin doesn't make any difference.
There doesn't appear to be any applications that are using
Stubborn
as their working directory.
Help!
Any ideas on what might be causing this?