The GetFileSize
function retrieves the size of the specified file. The size is returned in bytes.
GetFileSize
DWORD GetFileSize(
[in] HANDLE hFile,
[out, opt] LPDWORD lpFileSizeHigh
);
Parameters
Parameter | Type | Description |
---|---|---|
hFile |
HANDLE |
A handle to the file. This handle must have been created by the CreateFile function with the GENERIC_READ access right. |
lpFileSizeHigh |
LPDWORD |
A pointer to a doubleword that receives the high-order 32 bits of the file size. This parameter can be NULL if the file size is less than 4 GB. If this parameter is not NULL , the return value is the low-order 32 bits of the file size, and the value pointed to by lpFileSizeHigh is the high-order 32 bits. |
Return Value
Type | Description |
---|---|
DWORD |
If the file size is less than 4 GB and the lpFileSizeHigh parameter is NULL , the return value is the size of the file in bytes. If the file size is 4 GB or greater and the lpFileSizeHigh parameter is not NULL , the return value is the low-order 32 bits of the file size and the value pointed to by lpFileSizeHigh contains the high-order 32 bits of the file size. If an error occurs, the return value is INVALID_FILE_SIZE (0xFFFFFFFF). To get extended error information, call GetLastError . |
Remarks
To get the size of a file that may be larger than 4 GB, you must use the GetFileSizeEx
function.
If the file size is exactly 4 GB, the return value of GetFileSize
is 0 and the value pointed to by lpFileSizeHigh
is 1. The application should check for this case to correctly determine if the file size is 4 GB.
Note: This function is part of the Win32 API and is typically used for compatibility with older Windows versions. For new development, it is recommended to use
GetFileSizeEx
for better support of large files.
Requirements
Minimum supported client | Windows 2000 Professional |
Minimum supported server | Windows 2000 Server |
Header | windows.h |
Library | Kernel32.lib |
DLL | Kernel32.dll |