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

GetDiskFreeSpace gives information on the free space on a disk, the total space, and more! It puts four pieces of information into each of the numeric variables passed to it. A "cluster" is the actual unit of storage on a disk. A cluster can hold no more than 1 file, but a file can be spread across multiple clusters. A "sector" is a part of a cluster. You can calculate the cluster size in bytes by lpSectorsPerCluster * lpBytesPerSector. You can calculate the disk's free space by multiplying the cluster size by lpNumberOfFreeClusters, and the disk's total space by multiplying the cluster size by lpTotalNumberOfClusters. The function returns 0 if an error occured, or a non-zero value if it succeeded.

lpRootPathName
The root directory of the disk to get information on, such as "c:\" or "a:\"
lpSectorsPerCluster
Variable that receives the number of sectors in a cluster on the disk.
lpBytesPerSector
Variable that receives the number of bytes in a sector on the disk.
lpNumberOfFreeClusters
Variable that receives the number of unused, empty clusters on the disk.
lpTotalNumberOfClusters
Variable that receives the total number of clusters, used and unused, on the disk.

Example:

' Find the free space on the hard drive C:
x = GetDiskFreeSpace("c:\", SecPerClus, BytePerSec, FreeClus, TotalClus)
Debug.Print "Free space:"; SecPerClus * BytePerSec * FreeClus; "bytes"

Category: Files
Back to the index.


Back to Paul Kuliniewicz's Home Page
E-mail: Borg953@aol.com
This page is at http://members.aol.com/Borg953/api/functions/getdiskfreespace.html