Interesting drive display utility - eoredson - 12-09-2023
In this post is an interesting drive display utility which lists drive volumes and serial numbers using a shell to vol:
Code: (Select All) Rem Utility to display drives and volume and serial. PD 2023.
Dim Shared drives(26) As Integer
Dim Shared labels(26) As String
Dim Shared serial(26) As String
For i = 1 To 26
d$ = CheckDrive(i)
If d$ <> "" Then Print d$
Next
End
Function CheckDrive$ (i)
t$ = "tempfile.arg"
i$ = Chr$(i + 64) + ":"
j$ = "cd " + i$
Shell _Hide j$ + " > " + t$
Close
Open t$ For Input As #1
If EOF(1) = 0 Then
Line Input #1, s$
s$ = LCase$(s$)
If s$ = "path not found" Then
' eat
Else
Shell _Hide "vol " + i$ + " > " + t$
Close
Open t$ For Input As #1
z = 0
Do Until EOF(1)
Line Input #1, s$
If Len(s$) Then
z = -1
Exit Do
End If
Loop
If z Then
Close
Open t$ For Input As #1
x = 0
Do Until EOF(1)
Line Input #1, s$
'Print s$
If LCase$(s$) = "invalid drive specification" Then
Exit Do
Else
drives(i) = -1
If InStr(s$, " is ") Then
x = x + 1
' volume in drive C is Label
If x = 1 Then
labels(i) = Mid$(s$, InStr(s$, " is ") + 4)
End If
' volume serial number is xxxx-xxxx
If x = 2 Then
serial(i) = Mid$(s$, InStr(s$, " is ") + 4)
End If
End If
End If
Loop
End If
End If
End If
q$ = ""
If drives(i) Then
q$ = Chr$(i + 64) + ":\" + labels(i)
If Len(serial(i)) Then
q$ = q$ + " [" + serial(i) + "]"
End If
End If
CheckDrive = q$
End Function
RE: Interesting drive display utility - euklides - 01-29-2024
Works only with Windows "english" .
RE: Interesting drive display utility - MasterGy - 01-29-2024
this might work on linux and windows because it only uses internal commands.
Code: (Select All)
On Error GoTo nodrive
For drive = 0 To 25
drive$ = Chr$(65 + drive) + ":"
checkdrive = 1
ChDir drive$
If checkdrive Then Print drive$; " is available"
Next drive
On Error GoTo 0
End
nodrive:
checkdrive = 0
Resume Next
RE: Interesting drive display utility - a740g - 01-29-2024
(01-29-2024, 07:56 PM)MasterGy Wrote: this might work on linux and windows because it only uses internal commands.
Code: (Select All)
On Error GoTo nodrive
For drive = 0 To 25
drive$ = Chr$(65 + drive) + ":"
checkdrive = 1
ChDir drive$
If checkdrive Then Print drive$; " is available"
Next drive
On Error GoTo 0
End
nodrive:
checkdrive = 0
Resume Next
Without using error handlers and CHDIR:
Code: (Select All)
PRINT DriveExists("c")
FUNCTION DriveExists%% (driveLetter AS STRING)
DriveExists = _DIREXISTS(LEFT$(driveLetter, 1) + ":\")
END FUNCTION
RE: Interesting drive display utility - PhilOfPerth - 01-29-2024
Noice!
Can it also be made to diplay drive occupancy size?
RE: Interesting drive display utility - eoredson - 01-30-2024
(01-29-2024, 11:17 PM)PhilOfPerth Wrote: Noice!
Can it also be made to display drive occupancy size? Yes, you could easily shell to get drive free space:
Code: (Select All) Rem sample program to get drive space using shell. v1.1a PD 2024.
On Error GoTo Hell
Color 15
Input "Drive letters"; D$
Do
If InStr(D$, ":") Then D$ = Left$(D$, InStr(D$, ":") - 1) + Mid$(D$, InStr(D$, ":") + 1) Else Exit Do
Loop
Do
If InStr(D$, "\") Then D$ = Left$(D$, InStr(D$, "\") - 1) + Mid$(D$, InStr(D$, "\") + 1) Else Exit Do
Loop
F = 0
For L = 1 To Len(D$)
E$ = Mid$(D$, L, 1)
C# = GetDrive(E$)
If C# > 0# Then
Color 14
Print "Drive "; E$; " bytes free"; C#
F = F + 1
End If
101
Next
Color 15
If F Then Print "Drives found"; F Else Print "No drives found."
End
Hell:
Print "Invalid drive reading "; E$
Resume 101
End
Function GetDrive# (D$)
D$ = UCase$(D$)
If D$ >= "A" And D$ <= "Z" Then
D$ = D$ + ":\"
' create default file.
F$ = D$ + "unknown.ick"
Open F$ For Output As #1
Print #1, "testdatafile"
Close #1
' open shell of drive.
F$ = "DIR " + D$ + "unknown.ick > tempfile.arg"
Shell _Hide F$
Open "tempfile.arg" For Input As #1
Do
If EOF(1) Then Exit Do
Line Input #1, X$
X$ = LCase$(X$)
If X$ = "invalid drive specification" Then Exit Do
If InStr(X$, "bytes free") Then
X$ = Left$(X$, InStr(X$, "bytes free") - 1)
Z = InStr(X$, "dir(s)")
If Z Then X$ = Mid$(X$, InStr(X$, "dir(s)") + 7)
X$ = LTrim$(RTrim$(X$))
If Len(X$) Then
Do
Z = InStr(X$, ",")
If Z Then
X$ = Left$(X$, Z - 1) + Mid$(X$, Z + 1)
Else
Exit Do
End If
Loop
C# = Int(Val(X$))
GetDrive = C#
Exit Do
End If
End If
Loop
Close
Kill D$ + "unknown.ick"
Kill "tempfile.arg"
End If
End Function
|