2008-09-29 14 views

Répondre

18

Le procédé GetDrives() retourne une classe de DriveInfo qui a une DriveType de propriété qui correspond à l'énumération des 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. 
} 

Voici un exemple légèrement ajustée de MSDN qui affiche des informations pour toutes lecteurs:

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

FYI 'DriveType' renvoie' DriveType.Fixed 'pour les disques durs USB externes. –

4

DriveInfo.DriveType devrait fonctionner pour vous.

DriveInfo[] allDrives = DriveInfo.GetDrives(); 

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