簡體   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