1

我有这条线:

Directory.Delete(outputfiles, true);

如果我将其设置为,true那么它也应该删除子目录和文件。现在我检查了目录是空的,所以下次它会被删除。但在此目录中出现异常之前,我还有另外 4 个子目录,其中一个子目录中有一个大小约为 7 Mb 的 zip 文件。

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: 
4

1 回答 1

9

根据MSDN

如果递归参数为真,则用户必须对当前目录以及所有子目录具有写权限。

可能是用户没有写权限?

或者这个:

在某些情况下,如果您在文件资源管理器中打开了指定的目录,Delete 方法可能无法将其删除。

于 2013-08-13T08:26:50.117 回答