Given the letter of a drive, how can I determine what type of drive it is?
For example, whether E: is a USB drive, a network drive or a local hard drive.
Have a look at DriveInfo's DriveType property.
DriveInfo
DriveType
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); foreach (var drive in drives) { string driveName = drive.Name; // C:, E:, etc: System.IO.DriveType driveType = drive.DriveType; switch (driveType) { case System.IO.DriveType.CDRom: break; case System.IO.DriveType.Fixed: // Local Drive break; case System.IO.DriveType.Network: // Mapped Drive break; case System.IO.DriveType.NoRootDirectory: break; case System.IO.DriveType.Ram: break; case System.IO.DriveType.Removable: // Usually a USB Drive break; case System.IO.DriveType.Unknown: break; } }
1.4m articles
1.4m replys
5 comments
57.0k users