9. Программирование на Objective-C. Работа с файлами



#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    @autoreleasepool
    {
        NSFileManager *theFileManager = [[NSFileManager alloc] init];
        if ([theFileManager fileExistsAtPath:@"/etc/hosts"] == YES)
        {
            NSDictionary *theAttributes = [theFileManager attributesOfItemAtPath:@"/etc/hosts" error:nil];
            for (NSString *attribute in theAttributes)
            {
                NSLog(@"%@ = %@", attribute, [theAttributes objectForKey:attribute]);
            }
        }
        
        NSURL *theURL = [NSURL URLWithString:@"file:///Users/John/Documents/CodingStandards-Style.pdf"];
        NSURL *theOtherURL = [NSURL fileURLWithPath:@"/Users/John/Downloads/CodingStandards-Style.pdf"];
        [theFileManager moveItemAtURL:theURL toURL:theOtherURL error:nil];
        
        NSURL *theExampleURL = [NSURL fileURLWithPath:@"/Users/John/Documents/example.txt"];
        NSMutableString *theString = [NSMutableString stringWithContentsOfURL:theExampleURL
            encoding:NSUTF8StringEncoding error:nil];
        [theString appendFormat:@"example2"];
        [theString writeToURL:theExampleURL atomically:YES];
    }
    return 0;
}