¿Cómo detectar si alguna unidad específica es un disco duro?
-
02-07-2019 - |
Pregunta
En C #, ¿cómo detecta que una unidad específica es una unidad de disco duro, unidad de red, CDRom o disquete?
Solución
El método GetDrives () devuelve una clase DriveInfo que tiene una propiedad DriveType 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í hay un ejemplo ligeramente ajustado de MSDN que muestra información para todas las unidades:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}, Type {1}", d.Name, d.DriveType);
}
Otros consejos
DriveInfo.DriveType debería funcionar para ti.
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
}
Compruebe la clase System.IO.DriveInfo y la propiedad DriveType.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow