c describes two ways to determine the type of disk drive

  • 2020-05-30 20:57:47
  • OfStack

1. Use WINDOWS API


/// <summary> 
///  judge 1 Type of disk drive  
/// </summary> 
/// <param name="nDrive"> Contains the path to the drive root directory 1 A string </param> 
/// <returns>Long , return zero if the drive is not recognized. Returns if the specified directory does not exist 1 . If successful, use any of the following 1 Four constants specify the drive type: DRIVE_REMOVABLE .  DRIVE_FIXED .  DRIVE_REMOTE .  DRIVE_CDROM  or  DRIVE_RAMDISK</returns> 
[DllImport("Kernel32.dll", EntryPoint = "GetDriveTypeA", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern long GetDriveType(string nDrive);

2. Use System. IO DriveInfo


DriveInfo driveInfo = new DriveInfo(Drive);

Through driveInfo DriveType


Related articles: