Thursday, May 9, 2013

NSDictionary NSFileCreationDate example ios


Returns the value for the NSFileCreationDate key.
- (NSDate *)fileCreationDate
Return Value
The value for the NSFileCreationDate key, or nil if the dictionary doesn’t have an entry for the key.
Example of [NSDictionary NSFileCreationDate]
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDate *now = [NSDate date];
NSDictionary *creationDateAttr = [NSDictionary dictionaryWithObjectsAndKeys: now, NSFileCreationDate, nil];
NSDictionary *modificationDateAttr = [NSDictionary dictionaryWithObjectsAndKeys: now, NSFileModificationDate, nil];
[fileManager setAttributes:modificationDateAttr ofItemAtPath:path error:&err];
[fileManager setAttributes:creationDateAttr ofItemAtPath:path error:&err];
Example of [NSDictionary NSFileCreationDate]
NSDictionary* attributesDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath: path error: NULL];
NSDate* date = [attributesDictionary objectForKey: NSFileCreationDate];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

NSString* justDateString = [dateFormatter stringFromDate: date];
[dateFormatter release];
Example of [NSDictionary NSFileCreationDate]
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];
for(int i=0;i<[dirContents count];i++)
NSDictionary* attrs = [fm attributesOfItemAtPath:[dirContents objectAtIndex:i] error:nil];

    if (attrs != nil) {
        NSDate *date = (NSDate*)[attrs objectForKey: NSFileCreationDate];
        NSLog(@"Date Created: %@", [date description]);

    else {
        NSLog(@"Not found");