Get File creation Date

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Get File creation Date

 
0
  #1
Dec 12th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 2
Reputation: spaceppl is an unknown quantity at this point 
Solved Threads: 1
spaceppl spaceppl is offline Offline
Newbie Poster

Re: Get File creation Date

 
0
  #2
Dec 12th, 2008
  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: Get File creation Date

 
0
  #3
Dec 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 2
Reputation: spaceppl is an unknown quantity at this point 
Solved Threads: 1
spaceppl spaceppl is offline Offline
Newbie Poster

Re: Get File creation Date

 
1
  #4
Dec 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 60
Reputation: Grub is an unknown quantity at this point 
Solved Threads: 0
Grub Grub is offline Offline
Junior Poster in Training

Re: Get File creation Date

 
0
  #5
Dec 12th, 2008
Magic, thank you very much.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC