GetFreeSpace



Public Type ULong ' Unsigned Long
Byte1 As Byte
Byte2 As Byte
Byte3 As Byte
Byte4 As Byte
End Type

Public Type LargeInt ' Large Integer
LoDWord As ULong
HiDWord As ULong
LoDWord2 As ULong
HiDWord2 As ULong
End Type

Public Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, _
FreeBytesAvailableToCaller As LargeInt, _
TotalNumberOfBytes As LargeInt, _
TotalNumberOfFreeBytes As LargeInt) As Long

Function GetFreeSpace(strPath as String) As Double
Dim nFreeBytesToCaller As LargeInt
Dim nTotalBytes As LargeInt
Dim nTotalFreeBytes As LargeInt
strPath = Trim(strPath)

If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If

If GetDiskFreeSpaceEx(strPath, nFreeBytesToCaller, _
nTotalBytes, nTotalFreeBytes) <> 0 Then
GetFreeSpace = CULong( _
nFreeBytesToCaller.HiDWord.Byte1, _
nFreeBytesToCaller.HiDWord.Byte2, _
nFreeBytesToCaller.HiDWord.Byte3, _
nFreeBytesToCaller.HiDWord.Byte4) * 2 ^ 32 + _
CULong(nFreeBytesToCaller.LoDWord.Byte1, _
nFreeBytesToCaller.LoDWord.Byte2, _
nFreeBytesToCaller.LoDWord.Byte3, _
nFreeBytesToCaller.LoDWord.Byte4)
End If

End Function

Function CULong(Byte1 As Byte, Byte2 As Byte, _
Byte3 As Byte, Byte4 As Byte) As Double
CULong = Byte4 * 2 ^ 24 + Byte3 * 2 ^ 16 + Byte2 * 2 ^ 8 + Byte1
End Function

(getfreespace.html)- by Paolo Puglisi - Modifica del 25/3/2019