Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In C# how do you detect is a specific drive is a Hard Drive, Network Drive, CDRom, or floppy?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
153 views
Welcome To Ask or Share your Answers For Others

1 Answer

The method GetDrives() returns a DriveInfo class which has a property DriveType that corresponds to the enumeration of 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.   
}

Here is a slightly adjusted example from MSDN that displays information for all drives:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...