File size question in Win32

michaelh20

Senior member
Sep 4, 2000
482
0
0
I'm trying to get the file size in the most kosher way and I read that this is the proper way to do it, although 4 GB files are rare I guess.

I get a warning : C:\DirListen\DirListener.cpp(98) : warning C4307: '+' : integral constant overflow

This is obviously because MAXWORD + 1 overflows the constant - but what exactly am I supposed to store it in that is bigger than a DWORD ?

void DirListener::processFile(WIN32_FIND_DATA *info, const char* fullPath)
{
//std::cout << "Processed : "<< movedClassName << std::endl;
DWORD fileSize = 0;
fileSize = ((info->nFileSizeHigh * (MAXDWORD+1)) + info->nFileSizeLow);

}
 

bob4432

Lifer
Sep 6, 2003
11,726
45
91
not familiar with what you are dong, but fyi - in video editing, 4GB is not rare at all, as uncompressed minidv coming in as uncompressed avi is ~12GB/hour which is how adobe premiere brings it in.
 
Apr 30, 2005
81
0
66
You need to use 64-bit values. In Visual C++ ( which I assume you're using ), that would equate to unsigned __int64.

Example:

typedef unsigned __int64 U64;
U64 u64FileSize = info->nFileSizeHigh * ( DWORDMAX + 1I64 ) + info->nFileSizeLow;
 

michaelh20

Senior member
Sep 4, 2000
482
0
0
Thanks..

I am loading a text file into memory for some processing.

4 GB is probably not very likely :)
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
4G files not likely? Just about everyone is doing DVD backups these days and most are 4G or larger. And it's just bad form to intentionally leave a limitation in your program.
 

Continuity27

Senior member
May 26, 2005
516
0
0
The 4GB limitation is due to FAT32. NTFS has no such limitation.

If your partition is formatted using FAT32, you'll need a workaround to be able to deal with files greater than 4GB. Or just do a "convert x: /fs:ntfs" where x is the disk drive partition you wish to convert to NTFS.

EDIT: Ignore me for this particular topic, but it's good to know anyways.