WIN32_FIND_DATA Size problem


I use WIN32_FIND_DATA to get the size of files in a filelist. I have some probs with big files, means files that have GB values, like 4.4GB as a example.

HANDLE hFind = ::FindFirstFile(pCtx->m_strLocation,&FindData);
if (hFind)
pCtx->m_nSize = FindData.nFileSizeLow;   //(Vector, m_nSize = int64)

The rsult on small files are ok but with gigabyte allways a wrong size. Any idea why?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hi just check your files were compressed or not if they were compressed and decompress it then check
FindData.nFileSizeLow is the correct size only if the file is less than 4,294,967,295 bytes.

The documentation is very clear and easy to read.  The fact that the variables is named
is rather a clue.

    WIN32_FIND_DATA Structure

Wherein it says>> The size of the file is equal to (nFileSizeHigh * (MAXDWORD+1)) + nFileSizeLow

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OcranaAuthor Commented:
henry: The files are not compresed. The problem is that the GigaByte Value is missing.

DanRollins: Yes I know this, but the problem is that I do not get the gigabyte just the megabytes.
4.821.276.672 Bytes = Filesize. But I just get 821.276.672 Bytes)

Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

You need to take _int64 type.

union FS
  UINT64 fs64;
  UINT32 fs32[2];  

FS fs;
fs.fs32[0] =  FindData.nFileSizeLow;
fs.fs32[1] =  FindData.nFileSizeHigh;

the filesize is now in fs.fs64.
Or use a variable that can handle values greater than 4GB. For instance:
double d= fs.nFileSizeHigh * (MAXDWORD+1)) + fs.nFileSizeLow;
However, based on what you said (missing just the leading 4) I think your problem is with display output.  The value might be correct.  Put a breakpoint in the program and examine the variable values.
What technique are you using to format the output?
AndyAinscowFreelance programmer / ConsultantCommented:
if (hFind)
pCtx->m_nSize = FindData.nFileSizeLow;   //(Vector, m_nSize = int64)

Based on that I agree with DanRollins in that you are only taking the part of the file size across to your variable.
Specifically that code ignores any size part greater than 4GB.

If the code you posted is not complete then please post the complete code you use.  It might be something simple like you are using an equals (=) instead of a incrementing assignment (+=).
OcranaAuthor Commented:
I select this answer cause it was a good way to find the solution. Finaly, it  sounds crazy, but the Microsoft solution did not work in my software but I was able to find the right solution with this tip.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.