Windows obtains the file size and obtains the file size.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.