Returns True if a specified drive letter exists : Drive « File Path « VBA / Excel / Access / Word






Returns True if a specified drive letter exists

 

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Function DriveExists(DriveLetter As String) As Boolean
    Dim Buffer As String * 255
    Dim BuffLen As Long
   
    DLetter = Left(DriveLetter, 1)
    BuffLen = GetLogicalDriveStrings(Len(Buffer), Buffer)

    DriveExists = False
    For i = 1 To BuffLen
        If UCase(Mid(Buffer, i, 1)) = UCase(DLetter) Then
            DriveExists = True
            Exit Function
        End If
    Next i
End Function

Sub Main()
  Debug.Print DriveExists("c:\")
End Sub

 








Related examples in the same category

1.Get Drive Information
2.The TypeOfDrive Function
3.The NumberOfBytesFree Function
4.Returns the number of free bytes for a drive
5.Returns the total storage capacity for a drive
6.Returns a string that describes the drive type
7.Returns the number of drives
8.Returns the drive letter using an index
9.Display Drive information