I was using the filesystemobject to get the size of the fixed drives on my machine. However, the totalsize property returns a 20 GB drive and I only have an 8 GB drive. Is there any way to get the correct size, or do I need to do it a different way?
Printable View
I was using the filesystemobject to get the size of the fixed drives on my machine. However, the totalsize property returns a 20 GB drive and I only have an 8 GB drive. Is there any way to get the correct size, or do I need to do it a different way?
You can use GetFreeDiskSpaceEx.
Code:Private Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, lpFreeBytesAvailableToCaller As ULARGE_INTEGER, lpTotalNumberOfBytes As ULARGE_INTEGER, lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type ULARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Dim FreeUser As ULARGE_INTEGER
Dim Total As ULARGE_INTEGER
Dim FreeSys As ULARGE_INTEGER
Dim Temp As Currency
Dim fTemp As Currency
Private Sub Command1_Click()
GetDiskFreeSpaceEx "C:\", FreeUser, Total, FreeSys
CopyMemory Temp, Total, 8
CopyMemory fTemp, FreeUser, 8
Print "Total Space: " & (CCur(Temp) * 10000) / 1000000000 & " GB"
Print "Free Space: " & (CCur(fTemp) * 10000) / 1000000000 & " GB"
End Sub
Thanks Megatron