我尝试过这两种不同的功能,但它没有按预期工作。 How to determine if drive is external drive< - 此处提供的方法对于usb thumbdrive也会返回true。但是,我正在寻找外置硬盘。
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
if (d.DriveType == DriveType.Fixed && d.Name != "C:" + @"\"){}
答案 0 :(得分:-1)
DriveType枚举也有一个可移动属性:
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;
}
您可以查询类型。