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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With