Re: getting file creation date from NTFS
Re: getting file creation date from NTFS
- Subject: Re: getting file creation date from NTFS
- From: "Hank Heijink (Mailinglists)" <email@hidden>
- Date: Sat, 22 May 2010 12:36:45 -0400
On May 22, 2010, at 11:33 AM, Angelo Chen wrote:
> Hi,
> I'd like to get creation date of a file, here are the codes:
> NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:path traverseLink:YES]; NSLog(@"Dict %@", fileAttributes);
> This works if the file came from FAT or Mac OS X, but if it is in a NTFS volume, creation date is always wrong, I observe the Finder can display the creation date correctly, any idea how to obtain a creation date for files in NTFS? Thanks,
> Angelo
> This come from a NTFS:
> 2010-05-22 23:06:12.276 test1[2531:a0b] Dict { NSFileCreationDate = "2928613-08-09 15:06:42 +0800"; NSFileExtensionHidden = 0; NSFileGroupOwnerAccountID = 20; NSFileGroupOwnerAccountName = staff; NSFileHFSCreatorCode = 0; NSFileHFSTypeCode = 0; NSFileModificationDate = "2004-08-04 12:56:56 +0800"; NSFileOwnerAccountID = 501; NSFileOwnerAccountName = user1; NSFilePosixPermissions = 493; NSFileReferenceCount = 1; NSFileSize = 69120; NSFileSystemFileNumber = 2469; NSFileSystemNumber = 234881027; NSFileType = NSFileTypeRegular;}
Not sure if this helps you, but it looks like NTFS reports file creation date in milliseconds, instead of seconds. As a possible workaround, you could convert the date to an NSTimeInterval, divide by 1000 and convert it back to a date. I believe these creation dates are relative to 1970, so I would try this:
NSDate *wrongCreationDate = <the date you have>;
NSTimeInterval msSince1970 = [wrongCreationDate timeIntervalSince1970];
NSDate *rightCreationDate = [NSDate dateWithTimeIntervalSince1970: msSince1970 / 1000.0];
I don't know how you get the system to report the correct date in the first place...
Good luck,
Hank
_______________________________________________
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