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.
Syntax
BOOL WINAPI GetDiskFreeSpace(
__in LPCTSTR lpRootPathName,
__out LPDWORD lpSectorsPerCluster,
__out LPDWORD lpBytesPerSector,
__out LPDWORD lpNumberOfFreeClusters,
__out LPDWORD lpTotalNumberOfClusters
);
Parameters
- lpRootPathName [in]
-
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:\).
The calling application must have FILE_LIST_DIRECTORY access rights for this directory.
- lpSectorsPerCluster [out]
-
A pointer to a variable that receives the number of sectors per cluster.
- lpBytesPerSector [out]
-
A pointer to a variable that receives the number of bytes per sector.
- lpNumberOfFreeClusters [out]
-
A pointer to a variable that receives the total number of free clusters on the disk that are available to the user who is 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]
-
A pointer to a variable that receives the total number of clusters on the disk that are available to the user who is 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 Value
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 that is required by the
GetDiskFreeSpace function.
Symbolic link behavior—If the path points to a symbolic link, the operation is performed on the target.
Requirements
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Header | WinBase.h (include Windows.h) |
| Library | Kernel32.lib |
| DLL | Kernel32.dll |
| Unicode and ANSI names | GetDiskFreeSpaceW (Unicode) and GetDiskFreeSpaceA (ANSI) |
See Also
- Disk Management Functions
- GetDiskFreeSpaceEx
- GetDriveType
Send comments about this topic to Microsoft
Build date: 11/12/2009