Windows API Reference

GetFileSize

Retrieves the size of the specified file.

DWORD GetFileSize( HANDLE hFile, LPDWORD lpFileSizeHigh );

Parameters

Parameter Description
hFile A handle to the file. The handle must have been created with the GENERIC_READ or GENERIC_WRITE access right.
lpFileSizeHigh A pointer to a DWORD that receives the high-order bits of the file size. This parameter can be NULL if the file size fits within 32 bits.

Return Value

If the function succeeds, the return value is the low-order bits of the specified file's size, in bytes. If the file size fits within 32 bits, lpFileSizeHigh will be NULL or point to a value of 0.

If the function fails, the return value is INVALID_FILE_SIZE. To get extended error information, call GetLastError.

Note: If the file size is greater than 4 GB, the return value is INVALID_FILE_SIZE and the high-order bits are returned in the DWORD pointed to by lpFileSizeHigh.

Remarks

  • To get the size of a file, you must have been granted read access to the file.
  • To get the size of a file, use the CreateFile function with the GENERIC_READ or GENERIC_WRITE flag.
  • The returned size is the number of bytes from the beginning of the file to the end of the file.
  • If the file is empty, the size is 0.
  • The size is in bytes.
  • For files larger than 4 GB, use the 64-bit version of this function, GetFileSizeEx.

See Also