In C# System.IO.DriveInfo
has the property DriveType
.
System.IO.DriveType
is an enum:
public enum DriveType
{
Unknown = 0,
//
// Summary:
// The drive does not have a root directory.
NoRootDirectory = 1,
Removable = 2,
Fixed = 3,
Network = 4,
CDRom = 5,
Ram = 6,
}
I suspect that this is a volume without a drive letter. But using:
System.IO.DriveInfo.GetDrives();
doesn't list my volume without drive letter.
Is NoRootDirectory
used for any other type of volumes / drives or does System.IO.DriveInfo.GetDrives()
just not show them?
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