ON ERROR GOTO er1
FOR i = 1 TO 26
drive$ = CHR$(i + 64)
OPEN drive$ + ":\~.~" FOR INPUT AS #1: CLOSE #1
IF found THEN
IF found = 1 THEN PRINT drive$ ELSE PRINT drive$ + " not ready."
END IF
NEXT
END
er1:
er% = ERR
SELECT CASE er%
CASE 76
' Not found so do nothing.
found = 0
CASE 53
found = 1
CASE 68
found = 2
END SELECT
RESUME NEXT
The "not ready" is going to be the optical drive if it does not contain media. Error 68 is drive not ready.
We can't use CHDIR as it will not differentiate a drive not ready, therefore it would not show the optical drive at all.
~.~ simply denotes a file name no one should have. It triggers the error 53, file not found, which we ignore. Error 76 is drive not found.
Pete
If eggs are brain food, Biden takes his scrambled.
Something was changed in MinGW which is preventing some programs from being created successfully. You could try to separately install v3.4.0 for now and try Pete's example again.
12-10-2022, 09:06 AM (This post was last modified: 12-10-2022, 09:12 AM by eoredson.)
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
(12-10-2022, 09:06 AM)eoredson Wrote: Actually I was thinking more upon this:
Why not have the function return a string instead? Needing a global string variable for the drive type is clunky. Could make it so it returns two values for the "not found" cases such as "[NONE][BADROOT]" or something else.