Solved

An example of using GetFileAttributesEx ?

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

737 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