Search code examples
c#windows.net-coresystem.io.directory

System.IO.Directory.CreateDirectory - weirdest exception ever


so, I'm trying to create a following directory:

d:\temp\ak\ty\nul

Path is constructed in the loop, starting from: d:\temp and so on, creating non-existent directories along the way, so it first creates:

d:\temp\ak

then:

d:\temp\ak\ty

and.... then it comes to the last bit nul it throws this exception:

enter image description here

So, what's going on - where it took \.\nul from?

The code:

string z_base_path = @"d:\temp\ak\ty";
string z_extra_path = "nul";
string z_full_path = System.IO.Path.Combine(z_base_path, z_extra_path);

System.IO.Directory.CreateDirectory(z_full_path);

Solution

  • In Windows, nul is a reserved file name. No file or directory may be named that. Other reserved names include:

    • con
    • prn
    • aux
    • com{0-9}
    • lpt{0-9}