devxlogo

DriveType – Determine the type of a drive

DriveType – Determine the type of a drive

Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _    (ByVal lpRootPathName As String) As LongConst DRIVE_UNKNOWN = 0      ' type can't be determinedConst DRIVE_NO_ROOT_DIR = 1  ' wrong argumentConst DRIVE_REMOVABLE = 2Const DRIVE_FIXED = 3Const DRIVE_REMOTE = 4Const DRIVE_CDROM = 5Const DRIVE_RAMDISK = 6' Determine the type of a drive. If you pass a null string it returns' the type of the current drive'' Returns one of the DRIVE_* constants, and stores in the optional' DriveDescription argument a textual description of the resultFunction DriveType(ByVal DriveName As String, Optional DriveDescription As _    String) As Long    If Len(DriveName) = 0 Then        ' use NULL if a null string has been passed (default drive)        DriveName = vbNullString    Else        ' otherwise always provide a colon and backslash        DriveName = Left$(DriveName, 1) & ":"    End If        DriveType = GetDriveType(DriveName)    Select Case DriveType        Case DRIVE_UNKNOWN            DriveDescription = "(unknown)"        Case DRIVE_REMOVABLE            DriveDescription = "Removable Drive"        Case DRIVE_FIXED            DriveDescription = "Fixed Drive"        Case DRIVE_REMOTE            DriveDescription = "Remote Drive"        Case DRIVE_CDROM            DriveDescription = "CD-ROM"        Case DRIVE_RAMDISK            DriveDescription = "RAM Disk"        Case Else            ' this includes the DRIVE_NO_ROOT_DIR case            DriveDescription = ""    End SelectEnd Function

See also  5 Benefits of Using Time Tracking Software
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist