What kind of drive is "NoRootDirectory " (System.IO.DriveType.NoRootDirectory)?

I know that it's used for unassigned drive letters. You will of course not get them through GetDrives but try new System.IO.DriveInfo("B:").DriveType or such. It might be used for unformatted partitions (or unknown filesystems) as well, but I'm not totally sure (you would have to test whether you get Unknown or NoRootDirectory in that case). For completeness, you could also create garbage drives by going to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices and creating a drive X: pointing to \Device\Null for example and see what you get for those.

Actually, the documentation for the underlying WinAPI function GetDriveType is a bit clearer. It says:

The root path is invalid; for example, there is no volume mounted at the specified path.

I would translate "the root path is invalid" as "The kernel path \DosDevices\X: doesn't resolve/link to a valid filesystem directory object able to resolve a request for the path \."

Probably the sentence was written by somebody with Windows kernel knowledge. In this case I'd assume that my "garbage drives" from above would also give you this value, as well as any unassigned drive letters.

For a more detailed read about the things I just mentioned, check out http://www.osronline.com/article.cfm%5eid=107.htm if you are interested.


System.IO.DriveType.NoRootDirectory seems to be an misleadingly designation for "This drive letter is unused"

Testcode for all drives: All not found drives have the type DriveType.NoRootDirectory

foreach (char driveLetter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToArray())
{
    var driveInfo = new System.IO.DriveInfo(driveLetter.ToString() + ":\\");

    if(System.IO.DriveInfo.GetDrives().FirstOrDefault(o => o.Name[0] == driveLetter) == null)
        Console.WriteLine("// Not found: " + driveInfo.Name + " has DriveType: " + driveInfo.DriveType.ToString());
    else
        Console.WriteLine("//     found: " + driveInfo.Name + " has DriveType: " + driveInfo.DriveType.ToString());
}

Result:

// Not found: A:\ has DriveType: NoRootDirectory
// Not found: B:\ has DriveType: NoRootDirectory
//     found: C:\ has DriveType: Fixed
//     found: D:\ has DriveType: CDRom
// Not found: E:\ has DriveType: NoRootDirectory
// Not found: F:\ has DriveType: NoRootDirectory
// Not found: G:\ has DriveType: NoRootDirectory
// Not found: H:\ has DriveType: NoRootDirectory
// Not found: I:\ has DriveType: NoRootDirectory
// Not found: J:\ has DriveType: NoRootDirectory
// Not found: K:\ has DriveType: NoRootDirectory
// Not found: L:\ has DriveType: NoRootDirectory
// Not found: M:\ has DriveType: NoRootDirectory
// Not found: N:\ has DriveType: NoRootDirectory
// Not found: O:\ has DriveType: NoRootDirectory
//     found: P:\ has DriveType: Network
// Not found: Q:\ has DriveType: NoRootDirectory
//     found: R:\ has DriveType: Network
//     found: S:\ has DriveType: Network
// Not found: T:\ has DriveType: NoRootDirectory
// Not found: U:\ has DriveType: NoRootDirectory
//     found: V:\ has DriveType: Network
//     found: W:\ has DriveType: Fixed
//     found: X:\ has DriveType: Network
//     found: Y:\ has DriveType: Network
//     found: Z:\ has DriveType: Network

Tags:

C#

Drive