[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WIN32_FIND_DATA Size problem

Posted on 2010-01-01
7
Medium Priority
?
1,081 Views
Last Modified: 2013-11-20
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
Comment
Question by:Ocrana
7 Comments
 

Expert Comment

by:henry
ID: 26160063
hi just check your files were compressed or not if they were compressed and decompress it then check
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 1500 total points
ID: 26160738
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
 

Author Comment

by:Ocrana
ID: 26161208
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:js-profi
ID: 26161391
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 26164177
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
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 26164750
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
 

Author Closing Comment

by:Ocrana
ID: 31671888
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question