"NoRootDirectory " (System.IO.DriveType.NoRootDirectory) 是什么驱动器?
What kind of drive is "NoRootDirectory " (System.IO.DriveType.NoRootDirectory)?
在 C# 中 System.IO.DriveInfo
有 属性 DriveType
。
System.IO.DriveType
是一个枚举:
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,
}
我怀疑这是一个没有盘符的卷。但是使用:
System.IO.DriveInfo.GetDrives();
不列出没有驱动器盘符的卷。
NoRootDirectory
用于任何其他类型的卷/驱动器还是 System.IO.DriveInfo.GetDrives()
只是不显示它们?
System.IO.DriveType.NoRootDirectory
似乎是对“此驱动器号未使用”的误导性指定
所有驱动器的测试代码:所有未找到的驱动器的类型为 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());
}
结果:
// 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
//Check fixed local drive
string path= "C\MyFolder\myfile.txt";
string root = Path.GetPathRoot(path);
if (DriveInfo.GetDrives().FirstOrDefault(d => d.Name == root).DriveType == DriveType.Fixed)
{
MessageBox.Show(root);
}
我知道它用于未分配的驱动器号。您当然不会通过 GetDrives
获得它们,但可以尝试 new System.IO.DriveInfo("B:").DriveType
之类的。它也可能用于未格式化的分区(或未知文件系统),但我不完全确定(在这种情况下你必须测试你是否得到 Unknown
或 NoRootDirectory
)。为了完整起见,您还可以通过转至 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices
并创建一个指向 \Device\Null
的驱动器 X:
来创建垃圾驱动器,然后查看您得到的结果。
其实documentation for the underlying WinAPI function GetDriveType
更清楚一点。它说:
The root path is invalid; for example, there is no volume mounted at the specified path.
我会将“根路径无效”翻译为“内核路径 \DosDevices\X:
没有 resolve/link 到能够解析路径请求的有效文件系统目录对象 \
."
可能这句话是由具有 Windows 内核知识的人写的。在这种情况下,我假设上面的“垃圾驱动器”也会给你这个值,以及任何未分配的驱动器号。
要更详细地了解我刚才提到的内容,如果您有兴趣,请查看 http://www.osronline.com/article.cfm%5eid=107.htm。
在 C# 中 System.IO.DriveInfo
有 属性 DriveType
。
System.IO.DriveType
是一个枚举:
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,
}
我怀疑这是一个没有盘符的卷。但是使用:
System.IO.DriveInfo.GetDrives();
不列出没有驱动器盘符的卷。
NoRootDirectory
用于任何其他类型的卷/驱动器还是 System.IO.DriveInfo.GetDrives()
只是不显示它们?
System.IO.DriveType.NoRootDirectory
似乎是对“此驱动器号未使用”的误导性指定
所有驱动器的测试代码:所有未找到的驱动器的类型为 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());
}
结果:
// 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
//Check fixed local drive
string path= "C\MyFolder\myfile.txt";
string root = Path.GetPathRoot(path);
if (DriveInfo.GetDrives().FirstOrDefault(d => d.Name == root).DriveType == DriveType.Fixed)
{
MessageBox.Show(root);
}
我知道它用于未分配的驱动器号。您当然不会通过 GetDrives
获得它们,但可以尝试 new System.IO.DriveInfo("B:").DriveType
之类的。它也可能用于未格式化的分区(或未知文件系统),但我不完全确定(在这种情况下你必须测试你是否得到 Unknown
或 NoRootDirectory
)。为了完整起见,您还可以通过转至 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices
并创建一个指向 \Device\Null
的驱动器 X:
来创建垃圾驱动器,然后查看您得到的结果。
其实documentation for the underlying WinAPI function GetDriveType
更清楚一点。它说:
The root path is invalid; for example, there is no volume mounted at the specified path.
我会将“根路径无效”翻译为“内核路径 \DosDevices\X:
没有 resolve/link 到能够解析路径请求的有效文件系统目录对象 \
."
可能这句话是由具有 Windows 内核知识的人写的。在这种情况下,我假设上面的“垃圾驱动器”也会给你这个值,以及任何未分配的驱动器号。
要更详细地了解我刚才提到的内容,如果您有兴趣,请查看 http://www.osronline.com/article.cfm%5eid=107.htm。