Results 1 to 3 of 3

Thread: Find all Drives on a Computer

  1. #1
    Guest
    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

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Use the GetLogicalDriveStrings API, i.e.

    In a Module:
    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
    Example usage:
    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

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width