我有这一行:
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:
答案 0 :(得分:8)
根据MSDN:
如果recursive参数为true,则用户必须具有写入权限 当前目录以及所有目录的权限 子目录。
可能是用户没有写权限吗?
或者这个:
在某些情况下,如果您在File中打开了指定的目录 资源管理器,Delete方法可能无法删除它。