Skip to content

Instantly share code, notes, and snippets.

@ByteProject
Created November 16, 2010 09:05
Show Gist options
  • Save ByteProject/701599 to your computer and use it in GitHub Desktop.
Save ByteProject/701599 to your computer and use it in GitHub Desktop.
Basic example how to access file attributes in Cocoa
//
// 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