How to detect if any specific drive is a hard drive?

后端 未结 3 1779
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 19:41

In C# how do you detect is a specific drive is a Hard Drive, Network Drive, CDRom, or floppy?

3条回答
  •  心在旅途
    2020-12-05 20:20

    DriveInfo.DriveType should work for you.

    DriveInfo[] allDrives = DriveInfo.GetDrives();
    
    foreach (DriveInfo d in allDrives)
    {
        Console.WriteLine("Drive {0}", d.Name);
        Console.WriteLine("  File type: {0}", d.DriveType);
    }
    

提交回复
热议问题