• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get file creation date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get file creation date


  • Subject: Re: How to get file creation date
  • From: Sean Long <email@hidden>
  • Date: Mon, 8 Jul 2002 14:35:38 -0700

Thank you that solution works great! Are there very many instances where you can not do something in Cocoa and have to use Carbon? Should I learn Carbon? I have only been a Mac user since March, does Apple add to the Cocoa API often fixing problems like the one I had?

thanks again

Sean Long
Hailstone Software


On Monday, July 8, 2002, at 01:35 PM, Clark Mueller wrote:

It needs to be done via Carbon. Pass the following method a file path and it gives you back the creation date, as an NSDate.

- (NSDate *)creationDateForFile:(NSString *)filename{
// Returns the creation date for 'filename' as an NSDate.

FSRef ref;
FSCatalogInfo catalogInfo;
OSStatus status;
OSErr err;
NSTimeInterval seconds;
NSCalendarDate *epoch = [NSCalendarDate dateWithYear:1904 month:1 day:1 hour:0 minute:0 second:0 timeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];


status = FSPathMakeRef([filename fileSystemRepresentation], &ref, nil);
if(status != noErr){
return nil;
}

err = FSGetCatalogInfo(&ref, kFSCatInfoCreateDate, &catalogInfo, NULL, NULL, NULL);
if(err != noErr){
return nil;
}

seconds = (double)((unsigned long long)catalogInfo.createDate.highSeconds << 32) + (double)catalogInfo.createDate.lowSeconds + (double)catalogInfo.createDate.fraction / 0xffff;

return [epoch addTimeInterval:seconds];
}


On Monday, July 8, 2002, at 02:14 PM, Sean Long wrote:

I am relatively new to Cocoa programming and am working on porting my image conversion program, ImageGrinder, to MacOS X. My question is how do I get the creation time like that shown in Finders 'show info' panel. I could not find any way of doing it in NSFileManager so I tried the old C stat struct but st_ctime was returning different creation times than that of the Finder. Can I even do this in Cocoa or do I need to do some carbon hack?

Thanks

Sean Long
Hailstone Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: How to get file creation date (From: Clark Mueller <email@hidden>)

  • Prev by Date: Re: NSOutlineView: removing the selected items, what's the easy way?
  • Next by Date: Re: Starting Cocoa development - Developing for Jaguar
  • Previous by thread: Re: How to get file creation date
  • Next by thread: Re: How to get file creation date
  • Index(es):
    • Date
    • Thread