?
Solved

An example of using GetFileAttributesEx ?

Posted on 2000-03-06
5
Medium Priority
?
6,370 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 120 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

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!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

770 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