The GetDiskFreeSpace function retrieves information about the specified disk, including the amount of free space on the disk.
The GetDiskFreeSpace function cannot report volume sizes that are greater than 2 gigabytes (GB). To ensure that your application works with large capacity hard drives, use the GetDiskFreeSpaceEx function.
Parameters
lpRootPathName
[in] Pointer to a null-terminated string that specifies the root directory of the disk for which information is to be returned. If this parameter is NULL, the function uses the root of the current disk. If this parameter is a UNC name, it must include a trailing backslash (for example, \\MyServer\MyShare\). Furthermore, a drive specification must have a trailing backslash (for example, C:\).
Windows 95: The initial release of Windows 95 does not support UNC paths. Therefore, you must temporarily map the UNC path to a drive letter, query the free disk space on the drive, then remove the temporary mapping. Windows 95 OSR2 and later support UNC paths.
lpSectorsPerCluster
[out] Pointer to a variable that receives the number of sectors per cluster.
lpBytesPerSector
[out] Pointer to a variable that receives the number of bytes per sector.
lpNumberOfFreeClusters
[out] Pointer to a variable for the total number of free clusters on the disk that are available to the user associated with the calling thread.
If per-user disk quotas are in use, this value may be less than the total number of free clusters on the disk.
lpTotalNumberOfClusters
[out] Pointer to a variable for the total number of clusters on the disk that are available to the user associated with the calling thread.
If per-user disk quotas are in use, this value may be less than the total number of clusters on the disk.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
The GetDiskFreeSpaceEx function lets you avoid some of the arithmetic required by the GetDiskFreeSpace function.
Windows 95 OSR2 and later: The GetDiskFreeSpaceEx function is available beginning with Windows 95 OEM Service Release 2 (OSR2), and you should use it whenever possible. The GetDiskFreeSpaceEx function returns correct values for all volumes, including those that are larger than 2 GB.
Windows Me/98/95: For volumes that are larger than 2 GB, the GetDiskFreeSpace function may return misleading values. The function caps the values stored into *lpNumberOfFreeClusters and *lpTotalNumberOfClusters so as to never report volume sizes that are greater than 2 GB. On volumes that are smaller than 2 GB with an actual sectors per cluster greater than 64, *lpSectorsPerCluster will be capped at 64 and the values stored into *lpSectorsPerCluster, *lpNumberOfFreeClusters, and *lpTotalNumberOfClusters will be incorrect. That is because the operating system adjusts the values so that computations with them yield the correct volume size with the capped *lpSectorsPerCluster.
Windows Me/98/95: GetDiskFreeSpaceW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
Requirements
Client: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Unicode: Implemented as Unicode and ANSI versions. Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
See Also
Disk Management Functions, GetDiskFreeSpaceEx, GetDriveType
Requirements
Client: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Unicode: Implemented as Unicode and ANSI versions. Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
See Also
Disk Management Functions, GetDiskFreeSpaceEx, GetDriveType