Csharp/C#教程:如何检测任何特定驱动器是否是硬盘驱动器?分享


如何检测任何特定驱动器是否是硬盘驱动器?

在C#中,您如何检测特定驱动器是硬盘驱动器,网络驱动器,CDRom还是软盘?

方法GetDrives()返回一个DriveInfo类,该类具有与System.IO.DriveType的枚举对应的属性DriveType:

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

DriveInfo.DriveType应该适合你。

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

检查System.IO.DriveInfo类和DriveType属性。

上述就是C#学习教程:如何检测任何特定驱动器是否是硬盘驱动器?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

www.ctvol.com true Article Csharp/C#教程:如何检测任何特定驱动器是否是硬盘驱动器?分享

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1020717.html

(0)
上一篇 2022年1月5日 上午12:35
下一篇 2022年1月5日 上午12:37

精彩推荐