1

I have this line:

Directory.Delete(outputfiles, true);

If I set it to true then it should also delete subdirectories and files. Now I checked that the directory is empty so it will be deleted next time. But before the exception in this directory I had another 4 subdirectories and in one of them I had a zip file of about 7 Mb size.

System.IO.IOException was unhandled
  HResult=-2147024751
  Message=The directory is not empty.

  Source=mscorlib
  StackTrace:
       at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
       at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
       at Diagnostic_Tool_Blue_Screen.CreateDirectories.CreateDirectoriesAtConstructor() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\CreateDirectories.cs:line 35
       at Diagnostic_Tool_Blue_Screen.Form1..ctor() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Form1.cs:line 125
       at Diagnostic_Tool_Blue_Screen.Program.Main() in d:\C-Sharp\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Diagnostic Tool Blue Screen\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
Ramon Araujo
  • 1,743
  • 22
  • 31
DanielVest
  • 823
  • 4
  • 20
  • 39
  • Tried now again and same exception. And i checked twice now im in the directory in the explorer and its empty. – DanielVest Aug 13 '13 at 08:25
  • Now its working now the exception is not throw up. Strange. Not sure why. – DanielVest Aug 13 '13 at 08:27
  • from http://msdn.microsoft.com/en-us/library/fxeahc5f.aspx *The directory specified by path is read-only, or recursive is false and path is not an empty directory.* Is it possible the directory is read only? – Adriaan Stander Aug 13 '13 at 08:27
  • from the same source: `In some cases, if you have the specified directory open in File Explorer, the Delete method may not be able to delete it.` – Heslacher Aug 13 '13 at 08:28
  • Also read-only or files being accessed will cause failure. Is this a post-operation cleanup? (maybe you still have a file handle on the zip file that's open?) – Brad Christie Aug 13 '13 at 08:28
  • Are you able to do that operation manually? – Nilesh Aug 13 '13 at 08:29

1 Answers1

10

According to MSDN:

If the recursive parameter is true, the user must have write permission for the current directory as well as for all subdirectories.

Could be that the user doesn't have write permission?

Or this one:

In some cases, if you have the specified directory open in File Explorer, the Delete method may not be able to delete it.

Fiona - myaccessible.website
  • 14,481
  • 16
  • 82
  • 117
  • 2
    Im getting the same error when developing locally, it turns out that if you got the folder open in Explorer the exception will be thrown. – JOSEFtw Jan 08 '15 at 08:36