Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Disk Drive Capacity
#8
I've edited my original code to be slightly cleaner by using CONSTs for the KILOBYTE, MEGABYTE, etc. I've also put the aliased names in quotes, to make them easier to read. I've also changed the library declaration from using the Kernel32 DLL to just using the headers in the QB64 folder. I've also changed GetDiskFreeSpace from an INTEGER to LONG, as the return type is BOOL, which is 4 bytes.

Code: (Select All)

Option _Explicit

Const DRIVE_UNKNOWN = 0
Const DRIVE_NO_ROOT_DIR = 1
Const DRIVE_REMOVABLE = 2
Const DRIVE_FIXED = 3
Const DRIVE_REMOTE = 4
Const DRIVE_CDROM = 5
Const DRIVE_RAMDISK = 6

Const KILOBYTE = 1024
Const MEGABYTE = KILOBYTE ^ 2
Const GIGABYTE = KILOBYTE ^ 3
Const TERABYTE = KILOBYTE ^ 4
Const PETABYTE = KILOBYTE ^ 5

Declare CustomType Library
    Function GetDiskFreeSpace& Alias "GetDiskFreeSpaceExA" (lpDirectoryName As String, Byval lpFreeBytesAvailableToCaller As _Offset, Byval lpTotalNumberOfBytes As _Offset, Byval lpTotalNumberOfFreeBytes As _Offset)
    Function GetDriveType~& Alias "GetDriveTypeA" (lpRootPathName As String)
End Declare

Dim As _Unsigned _Integer64 totalFreeBytesOnDisk

If GetDiskFreeSpace("C:\", 0, 0, _Offset(totalFreeBytesOnDisk)) Then
    Select Case totalFreeBytesOnDisk
        Case Is < KILOBYTE
            Print Using "    ####, B Available"; totalFreeBytesOnDisk,
        Case Is < MEGABYTE And totalFreeBytesOnDisk >= KILOBYTE
            Print Using "####,.## KB Available"; (totalFreeBytesOnDisk / KILOBYTE)
        Case Is < GIGABYTE And totalFreeBytesOnDisk >= MEGABYTE
            Print Using "####,.## MB Available"; (totalFreeBytesOnDisk / MEGABYTE)
        Case Is < TERABYTE And totalFreeBytesOnDisk >= GIGABYTE
            Print Using "####,.## GB Available"; (totalFreeBytesOnDisk / GIGABYTE)
        Case Is < PETABYTE And totalFreeBytesOnDisk >= TERABYTE
            Print Using "####,.## TB Available"; (totalFreeBytesOnDisk / TERABYTE)
    End Select
End If

Select Case GetDriveType("C:\")
    Case DRIVE_UNKNOWN
        Print "Unkown drive type"
    Case DRIVE_NO_ROOT_DIR
        Print "Invalid path"
    Case DRIVE_REMOVABLE
        Print "Removable media"
    Case DRIVE_FIXED
        Print "Fixed media"
    Case DRIVE_REMOTE
        Print "Network media"
    Case DRIVE_CDROM
        Print "CD-ROM drive"
    Case DRIVE_RAMDISK
        Print "RAM disk"
End Select
Schuwatch!
Yes, it's me. Now shut up.
Reply


Messages In This Thread
Get Disk Drive Capacity - by BDS107 - 07-03-2023, 04:30 PM
RE: Get Disk Drive Capacity - by SMcNeill - 07-03-2023, 05:02 PM
RE: Get Disk Drive Capacity - by SagaraS - 07-03-2023, 05:39 PM
RE: Get Disk Drive Capacity - by Steffan-68 - 07-03-2023, 07:20 PM
RE: Get Disk Drive Capacity - by SagaraS - 07-03-2023, 07:31 PM
RE: Get Disk Drive Capacity - by Kernelpanic - 07-05-2023, 03:49 PM
RE: Get Disk Drive Capacity - by Ultraman - 07-05-2023, 03:56 PM
RE: Get Disk Drive Capacity - by Kernelpanic - 07-05-2023, 04:04 PM
RE: Get Disk Drive Capacity - by Steffan-68 - 07-05-2023, 05:24 PM
RE: Get Disk Drive Capacity - by Ultraman - 07-05-2023, 05:29 PM
RE: Get Disk Drive Capacity - by Ultraman - 07-05-2023, 04:02 PM
RE: Get Disk Drive Capacity - by SMcNeill - 07-05-2023, 04:42 PM
RE: Get Disk Drive Capacity - by Ultraman - 07-05-2023, 04:55 PM
RE: Get Disk Drive Capacity - by eoredson - 07-07-2023, 01:52 AM
RE: Get Disk Drive Capacity - by Ultraman - 07-07-2023, 12:01 PM



Users browsing this thread: 3 Guest(s)