• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1134
  • Last Modified:

WIN32_FIND_DATA Size problem

Hello,

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.

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

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

Ocrana
0
Ocrana
Asked:
Ocrana
1 Solution
 
henryCommented:
hi just check your files were compressed or not if they were compressed and decompress it then check
0
 
DanRollinsCommented:
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
    FileSizeLow
is rather a clue.

    WIN32_FIND_DATA Structure
    http://msdn.microsoft.com/en-us/library/aa365740(VS.85).aspx

Wherein it says>> The size of the file is equal to (nFileSizeHigh * (MAXDWORD+1)) + nFileSizeLow
0
 
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.
like:
4.821.276.672 Bytes = Filesize. But I just get 821.276.672 Bytes)

Ocrana
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
js-profiCommented:
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.
0
 
DanRollinsCommented:
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?
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
if (hFind)
{
pCtx->m_nSize = FindData.nFileSizeLow;   //(Vector, m_nSize = int64)
::FindClose(hFind);
}

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 (+=).
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now