I'm trying to find the creation date (NOT modification date) of a file.
Creation date doesn't appear to be in the attributes of a file, though modified date is.
I'm using this code..
NSFileManager* fm = [NSFileManager defaultManager]; NSString* path = [PathHelpers pathInDocumentsFolderWithFilename:FILE_NAME]; NSDictionary* attrs = [fm attributesOfItemAtPath:path error:nil]; if (attrs != nil) { return (NSDate*)[attrs objectForKey: NSFileCreationDate]; } else { return nil; }
This always returns nil. Typing 'po attrs' into the debugger to get the list of key/value pairs in the NSDictionary returns the following..
NSFileGroupOwnerAccountID = 20;
NSFileGroupOwnerAccountName = staff;
NSFileModificationDate = 2010-01-21 11:47:55 +0000;
NSFileOwnerAccountID = 501;
NSFileOwnerAccountName = ben;
NSFilePosixPermissions = 420;
NSFileReferenceCount = 1;
NSFileSize = 338;
NSFileSystemFileNumber = 2234;
NSFileSystemNumber = 42553324;
NSFileType = NSFileTypeRegular;
No creation date.. bah..
Anyone know another way of getting the creation date or does it just not exist in iOS?
Right-click the file and select Properties. In the Properties window, the Created date, Modified date, and Accessed date is displayed, similar to the example below.
This code actually returns the good creation date to me:
NSFileManager* fm = [NSFileManager defaultManager]; NSDictionary* attrs = [fm attributesOfItemAtPath:path error:nil]; if (attrs != nil) { NSDate *date = (NSDate*)[attrs objectForKey: NSFileCreationDate]; NSLog(@"Date Created: %@", [date description]); } else { NSLog(@"Not found"); }
Are you creating the file inside the App? Maybe that's where the problem is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With