I need to get the size of files. These files range in size from very small to 10's of gigabytes. Are there any c functions that work in both linux and windows to do this? I've seen fileinfo64 but that seems to be windows only and i haven't been able to determine the maximum size supported by stat.
Asked
Active
Viewed 735 times
2 Answers
3
Linux provides the stat64
call which should be the equivalent of fileinfo64
. I would simply use a #ifdef
to select the correct one.
In fact, a cursory google seems to indicate that stat64
is also available in Windows so it may be easier than you think.

paxdiablo
- 854,327
- 234
- 1,573
- 1,953
2
In Windows, you can use GetFileSize()
. The first parameter to this function is a handle to the file, and the second parameter takes a reference to a DWORD, which upon return will contain the high 32-bits of the file's size. The function returns the low 32-bits of the file's size.
For example
DWORD dwFileSizeLow;
DWORD dwFileSizeHigh;
HANDLE hFile;
hFile = CreateFile (/* Enter the thousands of parameters required here */);
if (hFile != INVALID_HANDLE_VALUE)
dwFileSizeLow = GetFileSize (hFile, &dwFileSizeHigh);
unsigned __int64 fullSize = (((__int64) dwFileSizeHigh) << 32) | dwFileSizeLow

dreamlax
- 93,976
- 29
- 161
- 209