The original design of Windows allowed us to work with very large files, so the original designer chose a 64-bit value to represent the file size. However, we generally do not exceed 4GB file size during daily processing. Therefore, Windows provides two federated types of data structures representing file sizes.
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; 64-bit signed number
} 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; 64-bit unsigned number
} Ularge_integer, *pularge_integer;
1. Get the logical size of the file
BOOL GetFileSizeEx (
HANDLE hfile; Open File Handle
Plarge_integer plifilesize; 64-bit signed file size structure pointer
);
2. Get the physical size of the file
DWORD Getcompressedfilesize (
Pctstr pszFileName; File path string
Pdword Pdwfilesizehigh; Pointer to a high 32-bit value to save the file size
);
The file returns a 64-bit unsigned file size, a low 32 value of the file size is returned by the return value, and the high 32-bit value is saved in the DWORD that the parameter Pdwfilesizehigh points to. The way to get the physical file size using the Ularge_integer structure is 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. The difference between logical size and physical size
For example, assuming that the logical size of a file is 100KB compressed and consumes only 85KB of physical space, then the size returned by the call GetFileSizeEx is 100KB, The call to Getcompressedfilesize returns the number of bytes that the file actually occupies on disk by 85KB.
Windows get File size