Get Freespace on > 2GB drives
![Visual Basic 6, or VB Classic Visual Basic 6, or VB Classic](https://www.fortypoundhead.com//assets/img/icons/v7/vb6.png)
This code will return the freespace on a drive even if it exceeds 2GB.
Original Author: Philip Decker
Inputs
Drive ie. "C:"
Assumptions
I saw lots of calculations for drive sizes but this one works for me and does not require calculations at all. It will return what Windows shows under properties on a drive. It even shows mapped network drives properly. Hope this code helps someone.
Returns
Drive size.
Side Effects
None.
API Declarations
Dim FB, BT, FBT As Currency
Dim DriveSize As String
Const Gigabyte = 1073741824
Const Megabyte = 1048576
Dim retval As Long
Private Declare Function GetDiskFreeSpace_FAT32 _
Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, _
FreeBytesToCaller As Currency, BytesTotal _
As Currency, FreeBytesTotal As Currency) _
As Long
Code
Public Function GetDriveInfo(DriveName As String) As String
retval = GetDiskFreeSpace_FAT32(Left(DriveName, 2), FB, BT, FBT)
FBT = FBT * 10000 'convert result to actual size in bytes
If FBT / Gigabyte < 1 Then 'If less than 1GB then show as MB
DriveSize = Format(FBT / Megabyte, "####,###,###") & " MB free"
Else 'Show as GB
DriveSize = Format(FBT / Gigabyte, "####,###,###.00") & " GB free"
End If
GetDriveInfo = "[" & DriveSize & "]"
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.