Date: 02-16-2022
Return to Index
created by gbSnippets
'Sometimes a programmer needs to know which of the A-Z letter
'drives are available. The GetLogicalDriveStrings API will do the job.
'It returns $nul separated list of drives, in format "c:\" + $nul for each drive.
'Primary Code:
Local sDrives As String 'buffer to hold return from API
sDrives = String$(94,".") 'size the buffer - '"c:\" + nul = 4 bytes x 26 possible letter drives = 94
GetLogicalDriveStrings 94, ByVal StrPTR(sDrives)
'sdrive will contain $nul separated drive list, upper case letters
'Compilable Example: (Jose Includes)
'This example first shows the list of drives in a MsgBox, then
'gives the drive type for each drive.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local sDrives As String 'buffer to hold return from API
Local i as long, iCount&
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
sDrives = String$(104," ") 'size the buffer - '"c:\" + nul = 4 bytes x 26 possible letter drives = 104
GetLogicalDriveStrings 1044, ByVal StrPTR(sDrives)
Replace Chr$(0) With " " In sDrives
MsgBox sDrives
Dim DriveList(25) As String '26 elements, 1 for each possible letter
For i = 65 to 90
If Instr(sDrives, Chr$(i)) Then
DriveList(iCount&) = Chr$(i) + ": " + DriveDesc(GetDriveType(Chr$(i)+":\"))
Incr iCount&
End If
Next i
MsgBox Join$(DriveList(), $crlf)
End If
End Function
'function to get description of drive type resulting from GetDriveType API
Function DriveDesc (i as long) as String
Select Case i
Case 0 : Function = "Unknown Type"
Case 1 : Function = "Does Not Exist"
Case 2 : Function = "Drive_Removable"
Case 3 : Function = "Drive_Fixed"
Case 4 : Function = "Drive_Remote"
Case 5 : Function = "Drive_CDROM"
Case 6 : Function = "Drive_RAMDisk"
End Select
End Function
'gbs_00153
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm