Solved

An example of using GetFileAttributesEx ?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 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 clear a vector as well as how to detect empty vectors in C++.

744 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

13 Experts available now in Live!

Get 1:1 Help Now