07-03-2023, 07:20 PM
(07-03-2023, 05:39 PM)SagaraS Wrote: In QB64 you can use a Windows API for this.I also found something like that.
Code: (Select All)
DECLARE DYNAMIC LIBRARY "kernel32"
function GetDiskFreeSpaceEx% alias "GetDiskFreeSpaceExA" (_
lpDirectoryName as STRING, _
lpFreeBytesAvailableToMe As _UNSIGNED LONG, _
lpTotalNumberOfBytes As _UNSIGNED LONG, _
lpTotalNumberOfFreeBytes As _UNSIGNED LONG)
END DECLARE
DIM DriveOrFolder AS STRING
DIM FreeBytesAvailableToMe AS _UNSIGNED LONG
DIM TotalBytes AS _UNSIGNED LONG
DIM FreeBytes AS _UNSIGNED LONG
DriveOrFolder = "C:\"
FetchResult = GetDiskFreeSpaceEx(DriveOrFolder, FreeBytesAvailableToMe, TotalBytes, FreeBytes)
PRINT "Path: '" + DriveOrFolder + "'"
PRINT "Path founding (1 - ok, 0 - ERROR):" + STR$(FetchResult)
PRINT "------------------------------------"
PRINT "TotalBytes: " + STR$(TotalBytes)
PRINT "FreeBytes Avilable To Me: " + STR$(FreeBytesAvailableToMe)
PRINT "FreeBytes: " + STR$(FreeBytes)
Edit:
If you use the data type _UNSIGNED _INTEGER64, you can read larger disk sizes.
_UNSIGNED LONG is for < 4 GB media.
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
Declare Dynamic Library "Kernel32"
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 totalFreeBytesOnDisk As _Unsigned _Integer64
If GetDiskFreeSpace("C:\", 0, 0, _Offset(totalFreeBytesOnDisk)) Then
Select Case totalFreeBytesOnDisk
Case Is < 1024
Print Using " ####, B Available"; totalFreeBytesOnDisk,
Case Is < (1024 ^ 2) And totalFreeBytesOnDisk >= 1024
Print Using "####,.## KB Available"; (totalFreeBytesOnDisk / 1024)
Case Is < (1024 ^ 3) And totalFreeBytesOnDisk >= (1024 ^ 2)
Print Using "####,.## MB Available"; (totalFreeBytesOnDisk / (1024 ^ 2))
Case Is < (1024 ^ 4) And totalFreeBytesOnDisk >= (1024 ^ 3)
Print Using "####,.## GB Available"; (totalFreeBytesOnDisk / (1024 ^ 3))
Case Is < (1024 ^ 5) And totalFreeBytesOnDisk >= (1024 ^ 4)
Print Using "####,.## TB Available"; (totalFreeBytesOnDisk / (1024 ^ 4))
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