Determine file creation date on iPhone OS?

I planned to write code whose logic was based on checking the creation date of a particular file in the My Documents folder. It turns out when I call - [NSFileManager attributesOfItemAtPath: error:], NSFileCreationDate is not one of the provided attributes.

Can't find file creation date?

Thanks.

+7
ios objective-c iphone cocoa-touch nsfilemanager
source share
2 answers

FileCreationDate really is part of the dictionary. Here is a method that receives the passed URI of the file and captures some of the attributes from the file:

- (NSDictionary *) attributesForFile:(NSURL *)anURI { // note: singleton is not thread-safe NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *aPath = [anURI path]; if (![fileManager fileExistsAtPath:aPath]) return nil; NSError *attributesRetrievalError = nil; NSDictionary *attributes = [fileManager attributesOfItemAtPath:aPath error:&attributesRetrievalError]; if (!attributes) { NSLog(@"Error for file at %@: %@", aPath, attributesRetrievalError); return nil; } NSMutableDictionary *returnedDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: [attributes fileType], @"fileType", [attributes fileModificationDate], @"fileModificationDate", [attributes fileCreationDate], @"fileCreationDate", [NSNumber numberWithUnsignedLongLong:[attributes fileSize]], @"fileSize", nil]; return returnedDictionary; } 
+8
source share

According to Apple Link , NSFileCreationDate is available in version 2.0+:

NSFileCreationDate The key in the file is an attribute dictionary whose value indicates the date the file was created.

The corresponding value is an NSDate object.

Available on iPhone OS 2.0 and later.

Declared in NSFileManager.h.

+1
source share

All Articles