如何检测是否任何特定的驱动器是硬盘驱动器? [英] How to detect if any specific drive is a hard drive?
本文介绍了如何检测是否任何特定的驱动器是硬盘驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C#中如何检测是一个特定的驱动器是硬盘驱动器,网络驱动器,CD-ROM或软盘?
In C# how do you detect is a specific drive is a Hard Drive, Network Drive, CDRom, or floppy?
推荐答案
该方法GetDrives()函数返回一个拥有对应System.IO.DriveType枚举属性的DriveType一个DriveInfo类:
The method GetDrives() returns a DriveInfo class which has a property DriveType that corresponds to the enumeration of System.IO.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一个小幅调整的例子,显示所有驱动器的信息:
Here is a slightly adjusted example from MSDN that displays information for all drives:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}, Type {1}", d.Name, d.DriveType);
}
这篇关于如何检测是否任何特定的驱动器是硬盘驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文