Solved

An example of using GetFileAttributesEx ?

Posted on 2000-03-06
5
5,874 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now