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; }
memmons
source share