2008-09-29 21 views

Respuesta

18

El método GetDrives() devuelve una clase DriveInfo que tiene una DriveType propiedad que corresponde a la enumeración de 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. 
} 

Aquí está un ejemplo ligeramente ajustado de MSDN que muestra la información para todos unidades:

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

FYI 'DriveType' devuelve' DriveType.Fixed 'para discos duros externos USB. –

4

DriveInfo.DriveType debería funcionar para usted.

DriveInfo[] allDrives = DriveInfo.GetDrives(); 

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