Search Tools Links Login

Get Freespace on > 2GB drives


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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 78 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.