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
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.
If an error occured, the function returns 0 (use GetLastError to determine the error code). If successful, the function returns a non-zero value.
None
' 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"
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