Re: Cocoa & File Attributes Confusion
Re: Cocoa & File Attributes Confusion
- Subject: Re: Cocoa & File Attributes Confusion
- From: email@hidden
- Date: Sun, 10 Feb 2002 16:45:50 -0800
On Sunday, February 10, 2002, at 01:01 PM, Clark S. Cox III wrote:
On Sunday, February 10, 2002, at 02:10 , Matt Ronge wrote:
Also, I can't figure out how to get a files creation date in Cocoa,
huh? How
is this done?
To be honest, I'm not sure.
The dictionary returned by fileAttributesAtPath:traverseLink: doesn't
contain the creation date.
Creation date isn't available through POSIX. If you look at struct
stat, it's not there. I would assume that this information is not
stored on UFS filesystems.
On HFS+, it is stored and can be retrieved using Carbon... something
like this should return the create date in UTC. (Note, the epoch could
be made static someplace... 1/1/1904 00:00:00 is the beginning of Carbon
time.) Also, the big complicated construction of seconds is silly,
since there's a billion seconds till the UInt32 overflows... you can
safely just add catalogInfo.createDate.lowSeconds to the epoch for
another 30 years or so... (and the fraction is always zero from my
experience)
- (NSDate *)creationDate:(NSString *)path
{
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([path fileSystemRepresentation], &ref, nil);
if (status != noErr) {
NSLog(@"error making ref for %@: %d", path, status);
return nil;
}
err = FSGetCatalogInfo(&ref, kFSCatInfoCreateDate, &catalogInfo,
NULL, NULL, NULL);
if (err != noErr) {
NSLog(@"error getting catalog info: %d", err);
return nil;
}
seconds = (double)((unsigned long
long)catalogInfo.createDate.highSeconds << 32) +
(double)catalogInfo.createDate.lowSeconds +
(double)catalogInfo.createDate.fraction / 0xffff;
return [epoch addTimeInterval:seconds];
}
_______________________________________________
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.