【问题标题】:How to discover usb mass storage device (external hard drive) ?如何发现 USB 大容量存储设备(外置硬盘)?
【发布时间】:2018-08-14 14:35:50
【问题描述】:

我已经尝试了这两种不同的功能,但它没有按预期工作。 How to determine if drive is external drive

       DriveInfo[] allDrives = DriveInfo.GetDrives();
       foreach (DriveInfo d in allDrives)     
       if (d.DriveType == DriveType.Fixed && d.Name != "C:" + @"\"){}

【问题讨论】:

  • 在您的估计中,是什么决定了任何特定的基于 USB 闪存的大容量存储设备是“硬盘驱动器”还是“拇指驱动器”?对于操作系统,区别在于分区。

标签: c# external usb-drive driveinfo


【解决方案1】:

DriveType 枚举也有一个 Removable 属性:

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;
}

您可以查询类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多