Windows get File size

Source: Internet
Author: User

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

Related Article

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.