在C#中,如何檢測特定驅動器是硬盤驅動器,網絡驅動器,CDRom還是軟盤?如何檢測是否有任何特定的驅動器是硬盤驅動器?
12
A
回答
18
方法GetDrives()返回,其具有對應於System.IO.DriveType的枚舉的屬性的DriveType一個DriveInfo類:
public enum DriveType
{
Unknown, // The type of drive is unknown.
NoRootDirectory, // The drive does not have a root directory.
Removable, // The drive is a removable storage device,
// such as a floppy disk drive or a USB flash drive.
Fixed, // The drive is a fixed disk.
Network, // The drive is a network drive.
CDRom, // The drive is an optical disc device, such as a CD
// or DVD-ROM.
Ram // The drive is a RAM disk.
}
下面是從一個MSDN略作調整例如,對於所有顯示信息驅動器:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}, Type {1}", d.Name, d.DriveType);
}
+0
僅供參考`DriveType`爲外部USB硬盤驅動器返回`DriveType.Fixed'。 – 2017-06-29 12:10:04
4
DriveInfo.DriveType應該爲你工作。
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
}
3
檢查System.IO.DriveInfo class和DriveType屬性。
相關問題
- 1. 如何檢查是否有任何讀/寫活動與C#特定的硬盤驅動器?
- 2. 如何確定驅動器是否是外置驅動器
- 3. 布爾檢查是否有任何驅動器包含特定的驅動器類型
- 4. 如何枚舉硬盤驅動器
- 5. 如何在Windows上引用特定的硬盤驅動器?
- 6. C++ \ Win32的信息有關的所有驅動器:硬盤驅動器,USB驅動器,光盤驅動器,軟盤驅動器等
- 7. Java堆硬盤驅動器
- 8. C#硬盤驅動器RPM
- 9. C# - 從硬盤驅動器
- 10. 檢查驅動器是否是主驅動器
- 11. 硬盤或硬盤驅動器
- 12. 如何檢測驅動器在C#中是否有回收站?
- 13. 如何檢測USB閃存驅動器的盤符USB閃存驅動器的
- 14. 通過BIOS的USB硬盤驅動器/筆驅動器仿真
- 15. 有沒有辦法檢測驅動器是否是SSD?
- 16. 檢測磁盤是否爲閃存驅動器
- 17. 檢測光盤是否在DVD驅動器中
- 18. 在Java中區分CD驅動器和硬盤驅動器
- 19. 如何從啓動盤訪問硬盤驅動器?
- 20. 如何阻止USB以阻止筆驅動器和外部硬盤驅動器
- 21. 在Linux中檢測安裝的硬盤驅動器
- 22. 如何從驅動器的全名獲得驅動器盤符
- 23. 驅動器檢測只檢測一個驅動器?
- 24. 確定CPU,內存或硬盤驅動器是否是Ruby腳本
- 25. 獲取硬盤的驅動器號
- 26. 模擬Linux中的硬盤驅動器
- 27. 帶硬盤驅動器的C++ IO
- 28. 殘破的硬盤驅動器診斷
- 29. 寫入硬盤驅動器的時間
- 30. 如何檢測USB驅動器是NTFS還是FAT32 in objective-c
正是我需要的!謝謝 – StubbornMule 2008-09-29 14:03:27