I'm assuming .NET DirectoryInfo and FileInfo objects are similar to Java's java.io.File, i.e. they represent abstract paths and aren't necessarily connected to existing physical paths.
I can do what I'm trying to do (empty out a folder and create it if it doesn't exist) in a different way that works, but I'd like to understand why this does not:
using System.IO;
namespace TestWipeFolder
{
internal class Program
{
private static void Main(string[] args)
{
var di = new DirectoryInfo(@"C:\foo\bar\baz");
if (di.Exists)
{
di.Delete(true);
}
// This doesn't work. C:\foo\bar is still there but it doesn't remake baz.
di.Create();
}
}
}
UPDATE: I tried the same code after a reboot and it worked fine. I still want to know what the similarities are to Java File objects and whether deleting a folder a DirectoryInfo object references can screw things up, but that is on the back burner now.