Reputation: 1645
I have code that creates a temp directory, does stuff, and then deletes the directory when it is done. The problem is that even though I specify true for the recursive parameter, it still throws an IOException saying "The directory is not empty". Here's what I have for code:
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)
}
Upvotes: 0
Views: 2168
Reputation: 1645
It appears that info.EnumerateFiles
was the issue. I got that idea from this answer.
I switched that to info.GetFiles
and I was then able to delete the directory after.
Upvotes: 1