Windows obtains the file size and obtains the file size.
The original design of Windows allowed us to process very large files, so the original designer used 64-bit values to indicate the file size. However, during daily processing, the file size generally does not exceed 4 GB. Therefore, Windows provides two combined data structures to indicate the file size.
// 64-bit signed form
Typedef union _ LARGE_INTEGER {
Struct {
DWORD LowPart; // low byte, 32-bit unsigned number
LONG HighPart; // high byte, 32-bit signed number
};
LONGLONG QuadPart; // The number of 64-Bit Signed parts.
} LARGE_INTEGER, * PLARGE_INTEGER;
// 64-bit unsigned form
Typedef union _ ULARGE_INTEGER {
Struct {
DWORD LowPart; // low byte, 32-bit unsigned number
DWORD HighPart; // high byte, 32-bit unsigned number
};
ULONGLONG QuadPart; // Number of 64-bit unsigned parts
} ULARGE_INTEGER, * PULARGE_INTEGER;
1. Obtain the logical size of the file
BOOL GetFileSizeEx (
HANDLE hFile; // opened file HANDLE
PLARGE_INTEGER pliFileSize; // 64-Bit Signed Format File Size Structure pointer
);
2. Obtain the physical size of the file
DWORD GetCompressedFileSize (
PCTSTR pszFileName; // file path string
PDWORD pdwFileSizeHigh; // pointer to the 32-bit value that saves the file size
);
The file returns a 64-bit unsigned file size. The low 32 value of the file size is returned through the return value. The high 32-bit value is stored in the DWORD indicated by the pdwFileSizeHigh parameter. You can use the ULARGE_INTEGER structure to obtain the size of a physical file as follows:
ULARGE_INTEGER ulFileSize;
UlFileSize. LowPart = GetCompressedFileSize (TEXT ("SomeFile. dat "),
&ulFileSize.HighPart);
The 64-bit unsigned file size is saved to ulFileSize. QuadPart.
3. Difference between logical size and physical size
For example, if the logical size of a file is KB after compression, the size returned by calling GetFileSizeEx is kb, the call to GetCompressedFileSize returns the actual bytes occupied by the file on the disk as 85KB.