Dim strDrives As String
Dim cbDrives As Long, cbRet As Long
Dim udtFreeBytesAvail As LargeInt, udtTtlBytes As LargeInt
Dim udtTTlFree As LargeInt
Dim dblFreeSpace As Double
Dim varDrives As Variant, varDrive As Variant
strDrives = String(512, 0)
cbDrives = Len(strDrives)
cbRet = GetLogicalDriveStrings(cbDrives, strDrives)
If cbRet > cbDrives Then
strDrives = String(cbRet + 1, 0)
cbDrives = Len(strDrives)
ElseIf cbRet = 0 Then
MsgBox "Function failed!"
Exit Sub
End If
strDrives = Left(strDrives, cbRet)
varDrives = Split(strDrives, Chr(0))
For Each varDrive In varDrives
If Not GetDriveType(varDrive) = DRIVE_REMOVABLE Then
If GetDiskFreeSpaceEx(varDrive, udtFreeBytesAvail, udtTtlBytes, udtTTlFree) Then
If udtFreeBytesAvail.lngLower 0 Then
dblFreeSpace = udtFreeBytesAvail.lngUpper * 2 ^ 32 + udtFreeBytesAvail.lngLower + 4294967296#
Else
dblFreeSpace = udtFreeBytesAvail.lngUpper * 2 ^ 32 + udtFreeBytesAvail.lngLower
End If
oFreeSpace.Add varDrive, dblFreeSpace
lstFreeSpaceEx.AddItem varDrive & " " & Format(dblFreeSpace, "#,###")
End If
End If
Next