检索有关驱动器的信息

检索有关驱动器的信息

本文介绍了检索有关驱动器的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我的电脑有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
}

推荐答案

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

Quote:

未知驱动器的类型未知。

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


这篇关于检索有关驱动器的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:59