在C中,如何检测特定驱动器是硬盘驱动器、网络驱动器、CDROM还是软盘?
最佳答案
方法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);
}
关于c# - 如何检测特定的驱动器是否为硬盘?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/148742/