Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interesting drive display utility
#1
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


Attached Files
.bas   checkdrive.bas (Size: 1.9 KB / Downloads: 31)
Reply
#2
Works only with Windows "english" .
Why not yes ?
Reply
#3
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
Reply
#4
(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
Reply
#5
Noice!
Can it also be made to diplay drive occupancy size?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#6
(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


Attached Files
.bas   bytefree.bas (Size: 1.95 KB / Downloads: 14)
Reply




Users browsing this thread: 2 Guest(s)