GetDiskFreeSpace Function

Declare Function GetDiskFreeSpace Lib "kernel32.dll" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long

Platforms

Description & Usage

GetDiskFreeSpace retrives information about the amount of space on a disk. This information includes the number of sectors in each cluster, the number of bytes in each sector, the number of free clusters, and the total number of clusters. Due to the limitations of the 32-bit integer data type, this function only works properly with disks with a capacity less than 2 MB. The replacement function GetDiskFreeSpaceEx does not have this limitation.

Return Value

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

Visual Basic-Specific Issues

None

Parameters

lpRootPathName
The root directory of the disk to get information on, such as "c:\" or "a:\"
lpSectorsPerCluster
32-bit integer variable which receives the number of sectors in a cluster on the disk.
lpBytesPerSector
32-bit integer variable which receives the number of bytes in a sector on the disk.
lpNumberOfFreeClusters
32-bit integer variable which receives the number of unused, empty clusters on the disk. Windows 2000: This may be lower than the actual value if per-user quotas are enabled.
lpTotalNumberOfClusters
32-bit integer variable which receives the total number of clusters, used and unused, on the disk. Windows 2000: This may be lower than the actual value if per-user quotas are enabled.

Example

' This code is licensed according to the terms and conditions listed here.

' Calculate and display the free and total space on drive C:
Dim secPerClus As Long  ' receives sectors per cluster
Dim bytePerSec As Long  ' receives bytes per sector
Dim freeClus As Long  ' receives number of free clusters
Dim totalClus As Long  ' receives total number of clusters
Dim retval As Long  ' return value

' Read the information into the variables
retval = GetDiskFreeSpace("c:\", secPerClus, bytePerSec, freeClus, totalClus)

' Display the information
Debug.Print "Free space:"; freeClus * secPerClus * bytePerSec; "bytes"
Debug.Print "Total space:"; totalClus * secPerClus * bytePerSec; "bytes"

See Also

GetDiskFreeSpaceEx

Category

Files

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: July 25, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getdiskfreespace.html