How do you look up what drives are available on a user's computer? I'm trying to find out what drive letters are available so I can search for files.
Thanks
Printable View
How do you look up what drives are available on a user's computer? I'm trying to find out what drive letters are available so I can search for files.
Thanks
Use the GetLogicalDriveStrings API, i.e.
In a Module:Example usage:Code:Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Function GetDrives() As Variant
Dim sDrive() As String
Dim sDrives As String
Dim nDrives As Long
sDrives = Space(255)
sDrives = Left(sDrives, GetLogicalDriveStrings(255, sDrives))
While Len(sDrives)
ReDim Preserve sDrive(nDrives)
sDrive(nDrives) = Left(sDrives, 3)
nDrives = nDrives + 1
sDrives = Mid(sDrives, 5)
Wend
GetDrives = sDrive
End Function
Code:Private Sub Command1_Click()
Dim vDrives As Variant
Dim nDrive As Long
vDrives = GetDrives
For nDrive = 0 To UBound(vDrives)
List1.AddItem vDrives(nDrive)
Next
End Sub
Code:Dim nLetter As Integer
Dim sDrive As String
Dim lType As Long
Dim intEntries As Integer
Const HARD = 3
Const A = 65
Const Z = 90
For nLetter = A To Z
sDrive = Chr(nLetter)
lType = GetDriveType(sDrive & ":\") ' API
If lType = HARD Then
frmResults.dirList.Path = sDrive & ":\"
g_nDirs = g_nDirs + frmResults.dirList.ListCount
End If
Next
[Edited by MartinLiss on 06-15-2000 at 12:14 PM]