Declare Function GetLogicalDriveStrings Lib "kernel32.dll" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Platforms: Win 95/98, Win NT
GetLogicalDriveStrings determines the valid logical drives on the computer and places the names of their root directories into the string passed as lpBuffer. Each root directory name in the buffer is separated by a null character, and the entire string ends in two null characters. For example, if only drives A: and C: exist, the string will be "a:\(null)c:\(null)(null)", where (null) represents the null character. The function returns 0 if an error occured, or the length of the string placed in lpBuffer if successful.
Example:
' List the names of all the root directories. Since each entry in the string takes
' four characters (three for the name and one for the null), we can "count by fours" going
' through the string until we reach the end. This frees us from worrying about nulls.
Dim drivenames As String ' receives list of root names
Dim thisdrive As String ' buffer for one extracted root directory name
Dim c As Long ' counter variable
Dim slength As Long ' receives length of returned string
' Make enough room in the buffer to receive the drive names.
drivenames = Space(255) ' more than enough room
' Get the root directory names of all logical drives.
slength = GetLogicalDriveStrings(255, drivenames) ' drivenames now holds the list
' Count by fours to extract the names of each drive.
For c = 1 To slength Step 4 ' loop with an increment of 4
thisdrive = Mid(drivenames, c, 3) ' extract a 3-character string X:\ (X is the drive letter)
Debug.Print thisdrive ' display the drive name
Next c
See Also: GetLogicalDrives
Category: Files
Go back to the alphabetical Function listing.
Go back to the Reference section index.
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getlogicaldrivestrings.html