Solved

An example of using GetFileAttributesEx ?

Posted on 2000-03-06
5
5,986 Views
Last Modified: 2010-05-18
Hi all,
do you have an example of using GetFileAttributesEx function, for example, retrieving the creation date of a file and the last modified date of this file ?
I am trying the following syntax:
LPCTSTR nom="D:\\model.mdb";
GET_FILEEX_INFO_LEVELS FileInfosLevel;
LPVOID lpInfoFile;
BOOL ret=::GetFileAttributesEx(nom, FileInfosLevel, lpInfoFile);

But ret returns always 0 (error)
Thanks for your help...
0
Comment
Question by:tradinfo
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 30 total points
ID: 2587704
the problem is you are not providing it with a buffer to return information in.

continues
0
 
LVL 22

Expert Comment

by:nietod
ID: 2587718
The last parameter is a pointer to a buffer __that you have provided__ that the procedure will fill in with the information you requested.  You are passing a pointer, but that pointer does not point to a buffer, that is an un-initialized pointer.  Usually you wouldn't even allocate a pointer for this.  you would allocate a local copy of the buffer then pass a pointer to it that is generated using &, like

LPCTSTR nom="D:\\model.mdb";
GET_FILEEX_INFO_LEVELS FileInfosLevel;
WIN32_FILE_ATTRIBUTE_DATA InfoFile;

BOOL ret=::GetFileAttributesEx(nom, FileInfosLevel, &InfoFile);

Let me know if you hve any questions.
0
 

Author Comment

by:tradinfo
ID: 2587875
Adjusted points to 30
0
 

Author Comment

by:tradinfo
ID: 2587876
Thanks!
An associated question to this one.
Once I have retrieved my datas in my InfoFile buffer, how may I get a "user comprehensive" result ?

E.g. the result of the following data:
FILETIME  ftCreationTime = InfoFile.ftCreationTime;
returns me :
dwLowDateTime=272
dwHighDateTime=10518368

How may I get the result under the form:
"Wednesday March 2000, 3rd  14:21:59"
???

Same question with the size of the file:
DWORD      nFileSizeHigh=InfoFile.nFileSizeHigh;
// nFileSizeHigh=10518548
DWORD      nFileSizeLow=InfoFile.nFileSizeLow;       
//nFileSizeLow=272

How may I know my file is 1 837 056 bytes ?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2587978
Usae FileTimetoSystemTime() to convert the filetime to its "components"  (year, month....)


The mathematical value of the file size is just HighSize*2^32+LowSize;
However in win32, an int cannot hold this large of a value.  It can only hold either half.  If you have 64 bit ints on your compiler (_int64) that can do it or  you have to use floating point (which mayl not be accurate to the exact byte)  If you use 64 bit ints, you can avoid power and multiply, by doing a bit shift like

Size =  (HghSize << 32) + LowSize;
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel/Word Add-in in what language? 5 118
Path to  STL Map header file 1 58
Safe conversion? 4 67
designing in object programming 12 77
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

772 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