gpt4 book ai didi

c# - 如何检测任何特定驱动器是否为硬盘驱动器?

转载 作者:可可西里 更新时间:2023-11-01 08:18:18 25 4
gpt4 key购买 nike

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

最佳答案

方法 GetDrives() 返回一个 DriveInfo 类,它有一个属性 DriveType,对应于 System.IO.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);
}

关于c# - 如何检测任何特定驱动器是否为硬盘驱动器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/148742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com