[英]Recursively deleting of directories in C# throws an exception
我正在嘗試刪除目錄及其所有內容,如下所示:
private static void CleanOrCreateDirectory(string directory)
{
if (Directory.Exists(directory)) Directory.Delete(directory, true);
Directory.CreateDirectory(directory);
}
在有關SO相關問題的各種答案中建議應采用標准方法。 但是,它不起作用。 我得到:
System.IO.IOException : The directory is not empty.
好吧,當然它不是空的,這就是重點! 我究竟做錯了什么?
調用Directory.Delete
時,有IOException原因的列表。請在此處刪除 : http : //msdn.microsoft.com/zh-cn/library/fxeahc5f.aspx
它列出了導致IOException的所有不同原因,可以假定其中列出了原因!
事實證明, Directory.Delete(name, true)
只是不執行它所說的。 有關解決方法,請參閱“ 無法使用Directory.Delete(path,true)刪除目錄”中的可接受答案。
謝謝@HaunsTM
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.