Подтвердить что ты не робот

Как определить, является ли какой-либо конкретный диск жестким диском?

В С#, каким образом вы обнаруживаете конкретный диск, это жесткий диск, сетевой диск, CDRom или дискета?

4b9b3361

Ответ 1

Метод 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);
    }

Ответ 2

DriveInfo.DriveType должен работать на вас.

DriveInfo[] allDrives = DriveInfo.GetDrives();

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