943,746 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3014
  • C++ RSS
Dec 12th, 2008
0

Get File creation Date

Expand Post »
Hi

is it possible to get the file creation date of files on the mac using c++? If so, may you assist me on how do I go about doing so?

Many thanks
Similar Threads
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Dec 12th, 2008
0

Re: Get File creation Date

C++ Syntax (Toggle Plain Text)
  1. do {
  2. FSRef ref;
  3. if (noErr != FSPathMakeRef((const UInt8 *)filePath, &ref, NULL))
  4. break;
  5. FSCatalogInfo catalogInfo;
  6. if (noErr != FSGetCatalogInfo(&ref, kFSCatInfoCreateDate, &catalogInfo, NULL, NULL, NULL))
  7. break;
  8. UTCDateTime createDate = catalogInfo.createDate;
  9. CFAbsoluteTime absTime;
  10. if (noErr != UCConvertUTCDateTimeToCFAbsoluteTime (&createDate, &absTime))
  11. break;
  12. CFGregorianDate gregorianDate = CFAbsoluteTimeGetGregorianDate (absTime, NULL);
  13. } while (false);

CFGregorianDate is a struct containing fields such as year, month, day etc.
Reputation Points: 12
Solved Threads: 1
Newbie Poster
spaceppl is offline Offline
2 posts
since Dec 2008
Dec 12th, 2008
0

Re: Get File creation Date

Many thanks for your contribution. Please may you explain it. I would rather understand than simply copy and paste. Please if you do not mind.

Many thanks.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Dec 12th, 2008
1

Re: Get File creation Date

basically:
FSPathMakeRef creates a FSRef object from a given file path.
This object is passed to FSGetCatalogInfo function which returns an info about the file. kFSCatInfoCreateDate is a flag that notifies you're interested only in the creation date. You can combine different flags to obtain information about the file, which returns in catalogInfo object. Since you're interested only in the creation time, you can then access it via catalogInfo.createDate field. It's saved as UTCTime object. If you want to convert it to readable format, you first need to convert it to absolute time (using UCConvertUTCDateTimeToCFAbsoluteTime), and then to CFGregorianDate by using CFAbsoluteTimeGetGregorianDate.

BTW, developer.apple.com is an excellent source of information, you can read about all these methods there.
Reputation Points: 12
Solved Threads: 1
Newbie Poster
spaceppl is offline Offline
2 posts
since Dec 2008
Dec 12th, 2008
0

Re: Get File creation Date

Magic, thank you very much.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Palindrome re-visited
Next Thread in C++ Forum Timeline: opening 2 files...?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC