특정 드라이브가 하드 드라이브인지 감지하는 방법은 무엇입니까?
-
02-07-2019 - |
문제
C#에서 특정 드라이브는 하드 드라이브, 네트워크 드라이브, CDROM 또는 플로피입니다.
해결책
getDrives () 메소드는 System.io.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);
}
다른 팁
DriveInfo.DriveType 당신을 위해 일해야합니다.
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
}
확인하다 System.io.driveInfo 클래스 및 드라이브 타입 속성.
제휴하지 않습니다 StackOverflow