2008-09-29 37 views

回答

18

方法GetDrives()返回,其具有對應於System.IO.DriveType的枚舉的屬性的DriveType一個DriveInfo類:

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); 
    } 
+0

僅供參考`DriveType`爲外部USB硬盤驅動器返回`DriveType.Fixed'。 – 2017-06-29 12:10:04

4

DriveInfo.DriveType應該爲你工作。

DriveInfo[] allDrives = DriveInfo.GetDrives(); 

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