Reputation: 12087
This has to be something silly but I just don't see it. So I have this code:
var dir = new DirectoryInfo("somedir");
if (dir.Exists) {
dir.Delete(true);
}
dir.Create();
If the directory DOESN'T EXIST the directory is created just fine. If the directory EXISTS then no directory is created. Why?
Upvotes: 3
Views: 834
Reputation: 18649
Try this:
var dir = new DirectoryInfo("somedir");
if (dir.Exists)
{
dir.Delete(true);
dir.Refresh();
}
dir.Create();
You need to refresh after the delete to update the state info.
Upvotes: 11