Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get size of file in windows

I have found this function GetFileSizeEx(), which returns the size of file in PLARGE_INTEGER that is formed by the union of structures.

typedef union _LARGE_INTEGER {
  struct {
    DWORD LowPart;
    LONG  HighPart;
  } ;
  struct {
    DWORD LowPart;
    LONG  HighPart;
  } u;
  LONGLONG QuadPart;
} LARGE_INTEGER, *PLARGE_INTEGER;

Is it same as if I'd call it structure of structures? How can I figure the file size that it has returned and how large information can it handle?

like image 948
Jason Avatar asked Aug 29 '11 00:08

Jason


1 Answers

You are probably misunderstanding what a union is. A file's length is obtained by

LARGE_INTEGER  len_li;
GetFileSizeEx (hFile, &len_li);
int64 len = (len_li.u.HighPart << 32) | len_li.u.LowPart;

Alternatively, you can access the 64 bit representation directly with modern compilers:

LARGE_INTEGER  len_li;
GetFileSizeEx (hFile, &len_li);
LONGLONG  len_ll = len_li.QuadPart;
like image 138
wallyk Avatar answered Oct 15 '22 18:10

wallyk