(12-10-2022, 09:06 AM)eoredson Wrote: Actually I was thinking more upon this:
Code: (Select All)Declare Library
Function GetDriveType& (d$)
End Declare
' declare library variables.
Dim Shared DriveType As String
' call drive type
For z = 1 To 26
x = DRIVEEXISTS(z)
If x = 0 Then
Print Chr$(z + 64) + ": "; DriveType
End If
Next
End
' check drive exists.
' returns -1 if drive not detected.
Function DRIVEEXISTS (V)
VarX$ = Chr$(V + 64) + ":\" + Chr$(0)
VarX = GetDriveType(VarX$)
DriveType = ""
Select Case VarX
Case 0
DriveType = "[UNKNOWN]"
Case 1
DriveType = "[BADROOT]"
Case 2
DriveType = "[REMOVABLE]"
Case 3
DriveType = "[FIXED]"
Case 4
DriveType = "[REMOTE]"
Case 5
DriveType = "[CDROM]"
Case 6
DriveType = "[RAMDISK]"
End Select
If VarX > 1 Then
DRIVEEXISTS = 0
Else
DRIVEEXISTS = -1
End If
End Function
That's pretty neat!
Rho had something at .rip similar using Win32 API...
Rhosigma: https://qb64forum.alephc.xyz/index.php?t...#msg128764
Code: (Select All)
Declare Library
Function GetLogicalDriveStringsA& (ByVal bufSize&, buffer$)
End Declare
'--- get available drives once during your program init procedure ---
Dim Shared allDrives$
buffer$ = Space$(112)
length% = GetLogicalDriveStringsA&(Len(buffer$), buffer$)
allDrives$ = ""
For position% = 1 To length% Step 4
allDrives$ = allDrives$ + Mid$(buffer$, position%, 1)
Next position%
'--- in your program flow test drives whenever needed (returns false(0) or true(-1)) ---
Print DRIVEEXISTS%("A")
Print DRIVEEXISTS%("B")
Print DRIVEEXISTS%("C")
Print DRIVEEXISTS%("D")
End
'--- a quick test function ---
Function DRIVEEXISTS% (drv$)
DRIVEEXISTS% = (InStr(allDrives$, UCase$(drv$)) > 0)
End Function
So far, I haven't come across anything that is strictly in QB64 that will go into a description like the program you posted, but, you could combine my code with yours and get...
Code: (Select All)
Declare Library
Function GetDriveType& (d$)
End Declare
On Error GoTo er1
' declare library variables.
Dim Shared As String DriveType, DriveStatus
' call drive type
For z = 1 To 26
x = DRIVEEXISTS(z)
If x = 0 Then
DriveStatus = "Active"
Open Chr$(z + 64) + ":\" + Chr$(0) For Input As #1: Close #1
Print Chr$(z + 64) + ": "; DriveType; " "; DriveStatus
End If
Next
End
er1:
er% = Err
Select Case er%
Case 76
' Not found so do nothing.
Case 53
DriveStatus = "Active"
Case 68
DriveStatus = "Not Ready"
End Select
Resume Next
' check drive exists.
' returns -1 if drive not detected.
Function DRIVEEXISTS (V)
VarX$ = Chr$(V + 64) + ":\" + Chr$(0)
VarX = GetDriveType(VarX$)
DriveType = ""
Select Case VarX
Case 0
DriveType = "[UNKNOWN]"
Case 1
DriveType = "[BADROOT]"
Case 2
DriveType = "[REMOVABLE]"
Case 3
DriveType = "[FIXED]"
Case 4
DriveType = "[REMOTE]"
Case 5
DriveType = "[CDROM]"
Case 6
DriveType = "[RAMDISK]"
End Select
If VarX > 1 Then
DRIVEEXISTS = 0
Else
DRIVEEXISTS = -1
End If
End Function
Now we get the drive, some details, and its ready status.
Pete