Created
November 16, 2010 09:05
-
-
Save ByteProject/701599 to your computer and use it in GitHub Desktop.
Basic example how to access file attributes in Cocoa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// FileAttributes.m | |
// | |
// Coded by Stefan Vogt. | |
// Released under the FreeBSD license. | |
// http://www.byteproject.net | |
// | |
NSFileManager *fileManager = [[NSFileManager alloc] init]; | |
// Get the file URL and convert it to a path (NSString). | |
NSURL *myFileURL = [self fileURL]; | |
NSString *myFilePath = [myFileURL path]; | |
// Get the file attributes. | |
NSDate *creationDate = [[fileManager attributesOfItemAtPath:myFilePath error:nil] fileCreationDate]; | |
NSDate *modDate = [[fileManager attributesOfItemAtPath:myFilePath error:nil] fileModificationDate]; | |
NSNumber *fSize = [NSNumber numberWithInt:([[fileManager attributesOfItemAtPath:myFilePath error:nil] fileSize])]; | |
NSLog(@"Creation Date: %@", creationDate); | |
NSLog(@"Modification Date: %@", modDate); | |
NSLog(@"File size: %@ bytes", fSize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment