Hello,
The GetDiskFreeSpaceEx Win32 API call should get it for you. Just change the letter of your disk drive in the Test routine (my external HD is drive E:). I'm not sure what the difference is between the Free and Availble values reported. They are identical on my system.
Code:
Option Compare Database
Option Explicit
Private Type LARGE_INTEGER
lowpart As Long
highpart As Long
End Type
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias _
"GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, _
lpFreeBytesAvailableToCaller As LARGE_INTEGER, lpTotalNumberOfBytes _
As LARGE_INTEGER, lpTotalNumberOfFreeBytes As LARGE_INTEGER) As Long
Sub Test()
Dim lResult As Long
Dim liAvailable As LARGE_INTEGER
Dim liTotal As LARGE_INTEGER
Dim liFree As LARGE_INTEGER
Dim dblAvailable As Double
Dim dblTotal As Double
Dim dblFree As Double
'Determine the Available Space, Total Size and Free Space of a drive
lResult = GetDiskFreeSpaceEx("E:\", liAvailable, liTotal, liFree)
'Convert the return values from LARGE_INTEGER to doubles
dblAvailable = CLargeInt(liAvailable.lowpart, liAvailable.highpart)
dblTotal = CLargeInt(liTotal.lowpart, liTotal.highpart)
dblFree = CLargeInt(liFree.lowpart, liFree.highpart)
'Display the results
Debug.Print "Available Space: " & dblAvailable & " bytes (" & _
Format(dblAvailable / 1024 ^ 3, "0.00") & " G) " & vbCr & _
"Total Space: " & dblTotal & " bytes (" & _
Format(dblTotal / 1024 ^ 3, "0.00") & " G) " & vbCr & _
"Free Space: " & dblFree & " bytes (" & _
Format(dblFree / 1024 ^ 3, "0.00") & " G) "
End Sub
Private Function CLargeInt(Lo As Long, Hi As Long) As Double
'This function converts the LARGE_INTEGER data type to a double
Dim dblLo As Double, dblHi As Double
If Lo < 0 Then
dblLo = 2 ^ 32 + Lo
Else
dblLo = Lo
End If
If Hi < 0 Then
dblHi = 2 ^ 32 + Hi
Else
dblHi = Hi
End If
CLargeInt = dblLo + dblHi * 2 ^ 32
End Function
HTH,
Bob