GetDiskFreeSpaceEx Function

Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, lpFreeBytesAvailableToCaller As ULARGE_INTEGER, lpTotalNumberOfBytes As ULARGE_INTEGER, lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long

Platforms

Description & Usage

GetDiskFreeSpaceEx determines information about the size of a disk. It finds the free space available to the current user, the total disk space, and the amount of free space (all in bytes). Each value is placed into a ULARGE_INTEGER structure which can hold the unsigned 64-bit integer values. (If your programming language supplies an intrinsic unsigned 64-bit integer data type, that can be used instead.)

Return Value

If an error occured, the function returns 0 (use GetLastError to retrieve the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues

Until Visual Basic implements an intrinsic unsigned 64-bit integer data type, the ULARGE_INTEGER data structure must be used.

Parameters

lpDirectoryName
The name of a directory on the disk to retrieve the size information about. While this can be the name of the disk's root directory, it doesn't have to be.
lpFreeBytesAvailableToCaller
Unsigned 64-bit integer variable which receives the amount of free disk space available, in bytes, to the user. Windows 2000: This may be lower than the actual value if per-user disk space quotas are enabled.
lpTotalNumberOfBytes
Unsigned 64-bit integer variable which receives the amount of total disk space, in bytes. Windows 2000: This may be lower than the actual value if per-user disk space quotas are enabled.
lpTotalNumberOfFreeBytes
Unsigned 64-bit integer variable which receives the amount of free disk space, in bytes.

Example

' Display the amount of free space on drive C:.  If possible, display the free space
' as a "regular" number.  If it is larger than a 32-bit value, display the number in
' hexadecimal becaue Visual Basic does not yet support unsigned 64-bit integers.
Dim userbytes As ULARGE_INTEGER ' receives space available to user
Dim totalbytes As ULARGE_INTEGER ' receives total space
Dim freebytes As ULARGE_INTEGER  ' receives free space
Dim buffer As String  ' used as buffer to build hexadecimal display string
Dim retval As Long  ' return value

' Determine the amount of free space available -- ignore the other values.
retval = GetDiskFreeSpaceEx("C:\", userbytes, totalbytes, freebytes)  ' information for C:
' If the value fits into a 31-bit integer (because VB doesn't support unsigned 32-bit integers),
' display its value in base 10.  If not, convert it to base 16 (hexadecimal) to display.
If freebytes.HighPart = 0 And (freebytes.LowPart &H80000000) = 0 Then  ' can display regularly
  Debug.Print "Free Space on C:"; freebytes.LowPart  ' no conversion is necessary
Else  ' convert the two halves into hexadecimal
  buffer = Hex(freebytes.LowPart)  ' convert low-order half into hex
  ' Add leading 0's if it isn't 8 digits long.
  If Len(buffer) < 8 Then buffer = String(8 - Len(buffer), "0") & buffer
  buffer = Hex(freebytes.HighPart) & buffer  ' add high-order word
  Debug.Print "Free Space on C: (hex): "; buffer  ' display hexadecimal equivalent
End If

Related Function

GetDiskFreeSpace

Category

Files

Back to the index.


Last Modified: July 24, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information

Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/g/getdiskfreespaceex.html