在 C# 中,您如何检测特定驱动器是硬盘驱动器、网络驱动器、CDRom 还是软盘?
StubbornMule
问问题
4468 次
3 回答
18
GetDrives() 方法返回一个 DriveInfo 类,该类具有对应于 System.IO.DriveType 枚举的 DriveType 属性:
public enum DriveType
{
Unknown, // The type of drive is unknown.
NoRootDirectory, // The drive does not have a root directory.
Removable, // The drive is a removable storage device,
// such as a floppy disk drive or a USB flash drive.
Fixed, // The drive is a fixed disk.
Network, // The drive is a network drive.
CDRom, // The drive is an optical disc device, such as a CD
// or DVD-ROM.
Ram // The drive is a RAM disk.
}
下面是一个来自 MSDN 的稍微调整的示例,它显示了所有驱动器的信息:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}, Type {1}", d.Name, d.DriveType);
}
于 2008-09-29T14:09:34.500 回答
4
DriveInfo.DriveType应该适合你。
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
}
于 2008-09-29T13:57:33.357 回答
3
检查System.IO.DriveInfo类和 DriveType 属性。
于 2008-09-29T13:57:56.383 回答