Re: How to get file creation date
Re: How to get file creation date
- Subject: Re: How to get file creation date
- From: Clark Mueller <email@hidden>
- Date: Mon, 8 Jul 2002 14:35:12 -0600
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.