如何确定给定的驱动器号是本地驱动器、映射驱动器还是 USB 驱动器? [英] How can I determine if a given drive letter is a local, mapped, or USB drive?
本文介绍了如何确定给定的驱动器号是本地驱动器、映射驱动器还是 USB 驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定驱动器的盘符,我如何确定它是什么类型的驱动器?
Given the letter of a drive, how can I determine what type of drive it is?
例如,E: 是 USB 驱动器、网络驱动器还是本地硬盘驱动器.
For example, whether E: is a USB drive, a network drive or a local hard drive.
推荐答案
Have a look at DriveInfo
's DriveType
property.
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
foreach (var drive in drives)
{
string driveName = drive.Name; // C:, E:, etc:
System.IO.DriveType driveType = drive.DriveType;
switch (driveType)
{
case System.IO.DriveType.CDRom:
break;
case System.IO.DriveType.Fixed:
// Local Drive
break;
case System.IO.DriveType.Network:
// Mapped Drive
break;
case System.IO.DriveType.NoRootDirectory:
break;
case System.IO.DriveType.Ram:
break;
case System.IO.DriveType.Removable:
// Usually a USB Drive
break;
case System.IO.DriveType.Unknown:
break;
}
}
这篇关于如何确定给定的驱动器号是本地驱动器、映射驱动器还是 USB 驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文