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