Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A thinking experiment, How can you tell
#4
Maybe this helps?
DriveType is one of the fields

(There might be unrelevant pieces in here; cut out from larger program)
Code: (Select All)
$Console:Only

Declare Library
  Function GetDriveTypeA& (nDrive As String)
  Function GetLogicalDriveStringsA (ByVal nBuff As Long, lpbuff As String)
End Declare
Declare Dynamic Library "Kernel32"
  Function GetVolumeInformationA (Drive As String, Label As String, ByVal nVol As Long, ByVal Serial As _Offset, ByVal Max As _Offset, ByVal Flags As _Offset, Sys As String, ByVal nSys As Long)
  'Function GetDiskFreeSpaceA (nDrive As String, Byval csectors As _Offset, Byval sbytes As _Offset, Byval cfree As _Offset, Byval ctotal As _Offset)
  Function GetDiskFreeSpaceExA& (ByVal lpDirectoryName As _Offset, ByVal lpFreeBytesAvailableToCaller As _Offset, ByVal lpTotalNumberOfBytes As _Offset, ByVal lpTotalNumberOfFreeBytes As _Offset)
End Declare

Type LogicalDiskType
  Letter As String
  DriveType As _Byte
  VolumeName As String
  FileSystem As String
  Serial As String
End Type
Dim Shared LogicalDisk(1000) As LogicalDiskType

Dim As Integer i, LDs
LDs = getDiskInfo
For i = 1 To LDs
  Print Using "## \\"; i; LogicalDisk(i).Letter;
  Print Using "(#) \          \"; LogicalDisk(i).DriveType; LogicalDisk(i).VolumeName;
  Print Using "\      \\      \"; LogicalDisk(i).FileSystem; LogicalDisk(i).Serial
Next i

Function getDiskInfo%
  Dim DList As String, Drive As String, ret As Long, DriveType As Long
  Dim Label As String, Serial As Long, nMax As Long, nFlags As Long, Sys As String
  Dim LDs As Integer
  ret = GetLogicalDriveStringsA(0, DList): If ret = 0 Then Exit Function
  DList = Space$(ret): ret = GetLogicalDriveStringsA(ret, DList): If ret = 0 Then Exit Function
  For n% = 65 To 90
    If InStr(DList, Chr$(n%)) Then
      Drive = Chr$(n%) + ":\" + Chr$(0): DriveType = GetDriveTypeA(Drive)
      Label = Space$(20): Sys = Space$(20)
      ret = GetVolumeInformationA(Drive, Label, Len(Label), _Offset(Serial), _Offset(nMax), _Offset(nFlags), Sys, Len(Sys))
      LDs = LDs + 1 'new one
      LogicalDisk(LDs).VolumeName = Left$(Label, _InStrRev(Label, Chr$(0)) - 1)
      LogicalDisk(LDs).Serial = Hex$(Serial)
      LogicalDisk(LDs).Letter = Left$(Drive, 2)
      LogicalDisk(LDs).DriveType = DriveType '0=unknown,1=NoRoot,2=Removable,3=Local,4=Network,5=CD,6=Ramdisk
      LogicalDisk(LDs).FileSystem = Left$(Sys, _InStrRev(Sys, Chr$(0)) - 1)
    End If
  Next n%
  getDiskInfo% = LDs
End Function
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply


Messages In This Thread
RE: A thinking experiment, How can you tell - by mdijkens - 03-31-2025, 10:32 AM



Users browsing this thread: 1 Guest(s)