我有代码创建临时目录,做东西,然后在完成后删除目录。问题是即使我为递归参数指定了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)
}