Simple Drive Display
#11
(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
Reply


Messages In This Thread
Simple Drive Display - by eoredson - 12-10-2022, 04:43 AM
RE: Simple Drive Display - by Pete - 12-10-2022, 06:58 AM
RE: Simple Drive Display - by eoredson - 12-10-2022, 07:21 AM
RE: Simple Drive Display - by mnrvovrfc - 12-10-2022, 07:41 AM
RE: Simple Drive Display - by Pete - 12-10-2022, 07:57 AM
RE: Simple Drive Display - by Pete - 12-10-2022, 08:28 AM
RE: Simple Drive Display - by eoredson - 12-10-2022, 08:50 AM
RE: Simple Drive Display - by Pete - 12-10-2022, 08:58 AM
RE: Simple Drive Display - by eoredson - 12-10-2022, 09:06 AM
RE: Simple Drive Display - by mnrvovrfc - 12-10-2022, 09:16 AM
RE: Simple Drive Display - by Pete - 12-10-2022, 05:39 PM
RE: Simple Drive Display - by eoredson - 12-11-2022, 02:43 AM
RE: Simple Drive Display - by mnrvovrfc - 12-11-2022, 08:20 AM
RE: Simple Drive Display - by eoredson - 12-11-2022, 03:00 AM
RE: Simple Drive Display - by Pete - 12-11-2022, 03:45 AM
RE: Simple Drive Display - by eoredson - 12-11-2022, 05:30 AM
RE: Simple Drive Display - by eoredson - 12-12-2022, 05:38 AM
RE: Simple Drive Display - by Pete - 12-12-2022, 06:10 AM
RE: Simple Drive Display - by SMcNeill - 12-12-2022, 06:22 AM
RE: Simple Drive Display - by eoredson - 12-13-2022, 05:53 AM
RE: Simple Drive Display - by SpriggsySpriggs - 12-13-2022, 03:00 PM
RE: Simple Drive Display - by Pete - 12-13-2022, 03:22 PM
RE: Simple Drive Display - by SpriggsySpriggs - 12-13-2022, 04:21 PM
RE: Simple Drive Display - by Pete - 12-13-2022, 04:33 PM
RE: Simple Drive Display - by SpriggsySpriggs - 12-13-2022, 06:09 PM
RE: Simple Drive Display - by Pete - 12-13-2022, 07:05 PM
RE: Simple Drive Display - by vince - 12-13-2022, 10:25 PM
RE: Simple Drive Display - by Pete - 12-13-2022, 10:46 PM



Users browsing this thread: 12 Guest(s)