繁体   English   中英

如何检测可移动驱动器是笔式驱动器还是外部硬盘

[英]How to detect whether removable drive is pen-drive or external hard disk

我想检测可移动驱动器是笔式驱动器还是外部硬盘。

我有以下代码:

        DriveInfo[] allDrives = DriveInfo.GetDrives();

        foreach (DriveInfo drive in DriveInfo.GetDrives())
        {
            if (drive.DriveType == DriveType.Removable)
            {
              //Here I want to detect whether removable drive is 
              //Pendrive or External Hard Disk
            }
        }

非常感谢您的建议。

我只是跑在我的电脑测试,看看它返回我的驱动器何种类型和DriveType为我的USB驱动器是DriveType.Removable和我的外部硬盘驱动器(通过USB线连接)被DriveType.Fixed同我的C盘

根据msdn

DriveType.Removeable

该驱动器是可移动存储设备,例如软盘驱动器或USB闪存驱动器。

DriveType.Fixed

该驱动器是固定磁盘。

所以我假设DriveType.Fixed还包括外部HDD

如何区分内部硬盘驱动器和外部硬盘驱动器,有人在这里回答*,虽然我没有测试

*此外,关于该问题的OP提到他的外部HDD被识别为DriveType.Fixed

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM