C#getdrives类型固定但没有usb硬盘?

Eph*_*aim 5 c# usb hard-drive getdrivetype

我想检索系统中的固定磁盘列表.但C#的GetDrives固定驱动器包括插头USB硬盘.

知道如何检测到固定驱动器不是USB硬盘或反之亦然吗?

Wae*_*oul 3

使用 DriveType 检测驱动器的类型:

using System.IO;

DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
  if (d.IsReady && d.DriveType == DriveType.Fixed)
  {
    // This is the drive you want...
  }
}
Run Code Online (Sandbox Code Playgroud)

驱动信息类

编辑1:

检查以下链接: 如何检测硬盘驱动器是否通过 USB 连接?