检索有关驱动器的信息 [英] Retrieve information about a drive
问题描述
您好,
我的电脑有5个驱动器
CDEFG
硬盘驱动器有2个分区
我怎么知道驱动器C或D或E或F或G
属于硬盘,一个或多个可能属于usb(闪存)
我的目标是将数据写入硬盘我的意思是第二部分
的硬盘更可靠D
但D不是alaways第二部分硬盘
Hello,
My computer has 5 drives they are
C D E F G
the hard disk drive has 2 partition
How can i know that drive C or D or E or F or G
is belong to the hard disk, one or more could belong to usb(flash)
my goal is to write data to the hard disk i mean to the 2nd partion
of the hard disk which is more likley D
but D is not alaways 2nd partion of the hard disk
int i;
string[] strArr = new string[16];
DriveInfo[] allDrives = DriveInfo.GetDrives();
i = 0;
foreach (DriveInfo d in allDrives)
{
strArr[i] = d.Name;
i++;
// is d.Name hard disk or usb or cd etc
}
推荐答案
许多(如果不是全部)新PC都有恢复分区,它们是硬盘的第二个分区。大多数供应商会建议更改恢复分区中的数据不符合您的最佳利益。
您可以使用System.Io.DriveType
枚举以区分驱动器类型。
以下示例选择光驱(CD或DVD)。
Many, if not all, new PCs have Recovery Partitions that are the second partition of a hard drive. Most vendors would advise that it is not in your best interest to alter data in the Recover Partition.
You can useSystem.Io.DriveType
enumeration to differentiate drive type.
The example below selects the optical drive (CD or DVD).
string[] Drives = System.IO.Directory.GetLogicalDrives();
foreach (string strDrive in Drives) {
System.IO.DriveInfo di = new System.IO.DriveInfo(strDrive.Substring(0, 1).ToUpper());
// Optical Drive (CD or DVD)
if (di.DriveType == System.IO.DriveType.CDRom) {
strDVD = strDrive.Substring(0, 2);
// example: F:
}
}
可以使用以下内容找到硬盘:
A hard disk would be found using:
if (di.DriveType == System.IO.DriveType.Fixed) {
System.IO.DriveType Enumeration
System.IO.DriveType Enumeration
未知驱动器的类型未知。
NoRootDirectory驱动器没有根目录。
可移动驱动器是可移动存储设备,例如软盘驱动器或USB闪存驱动器。
固定驱动器是固定磁盘。
网络驱动器是网络驱动器。
CDRom驱动器是光盘设备,例如CD或DVD-ROM。
Ram驱动器是一个RAM磁盘。
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.
int i;
string[] strArr = new string[16];
DriveInfo[] allDrives = DriveInfo.GetDrives();
i = 0;
foreach (DriveInfo d in allDrives)
{
strArr[i] = d.Name;
i++;
MessageBox.Show("Type of Drive is "+d.Drive.Type.ToString());
}
这篇关于检索有关驱动器的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!