Re: getting file creation date from NTFS
Re: getting file creation date from NTFS
- Subject: Re: getting file creation date from NTFS
- From: Angelo Chen <email@hidden>
- Date: Sun, 23 May 2010 18:33:41 +0800 (HKT)
Hi,
I think FSGetCatalogInfo (&ref, kFSCatInfoCreateDate, &info, NULL, NULL, NULL); info.createDate has the creation date, can see it clearly in debugger, problem is, how to convert it into NSDatefollowing code taken from net works with UTC dates from OS X or FAT files, but not working with NTFS files, how to adjust this code to be able to convert NTFS file's date as well?
static NSTimeInterval CarbonReferenceDate( ){ static NSTimeInterval sCarbonReferenceDate = 0; if( sCarbonReferenceDate == 0 ) { NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; NSDate *ref = [[NSCalendarDate alloc] initWithYear: 1904 month: 1 day: 1 hour: 0 minute: 0 second: 0 timeZone: gmt]; sCarbonReferenceDate = [ref timeIntervalSinceReferenceDate]; [ref release]; } return sCarbonReferenceDate;}
static NSDate* UTCDateTimeToNSDate( UTCDateTime *utc ){ NSTimeInterval utcTime = *(unsigned long long*)utc / 65536.0; return [NSDate dateWithTimeIntervalSinceReferenceDate: CarbonReferenceDate() + utcTime];}
static void NSDateToUTCDateTime( NSDate* date, UTCDateTime *utc ){ *(unsigned long long*)utc = ([date timeIntervalSinceReferenceDate] - CarbonReferenceDate()) * 65536.0;}
--- 2010年5月23日 星期日,Ken Thomases <email@hidden> 寫道﹕
寄件人: Ken Thomases <email@hidden>
主題: Re: getting file creation date from NTFS
收件人: "Paul Sanders" <email@hidden>
副本(CC): "Angelo Chen" <email@hidden>, email@hidden
日期: 2010年5月23日,星期日,下午5:56
On May 23, 2010, at 4:19 AM, Paul Sanders wrote:
> Assuming that these figures come from stat (man -S 2 stat for details), it should be in something called st_birthtime.
Yes, although the stat structure only has the st_birthtimespec field if you build with 64-bit inodes enabled. This is the default on Snow Leopard or for 64-bit, but not for 32-bit on Leopard or earlier. Unfortunately, it seems that FSMegaInfo is not 64-bit-inode aware. It will never print the birth time.
It's not hard to update it to be aware of that, though.
> st_atime refers to the last time the file was accessed. So, either call stat yourself or, better perhaps, go via the file manager:
>
> http://developer.apple.com/mac/library/DOCUMENTATION/Carbon/Reference/File_Manager/Reference/reference.html
FSMegaInfo can be used to exercise that API, too. It's not just for 'stat'. To get the creation date:
./FSMegaInfo -vv FSGetCatalogInfo -kFSCatInfoCreateDate /path/to/file
or, for everything:
./FSMegaInfo -vv FSGetCatalogInfo -kFSCatInfoGettableInfo /path/to/file
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden