0
我有創建臨時目錄,執行任務,然後在完成時刪除目錄的代碼。問題是,即使我爲遞歸參數指定了true,它仍然會拋出IOException異常,說「該目錄不是空的」。 這裏就是我有下面的代碼:Directory.Delete(path,true)拋出IOException異常「目錄不爲空」
DirectoryInfo info = Directory.CreateDirectory(Path.Combine(tempdir, "temp"));
try{
PopulateDir(info);
foreach (FileInfo file in info.EnumerateFiles("*.*", SearchOption.AllDirectories)){
DoStuff(file);
}
}
finally{
info.Delete(true);// note: this is apparently functionally identical to Directory.Delete(info.FullName, true)
}