Take the 2-minute tour ×

I am a new to Objective-c, I want to get the detail infomation for the local directory (like name, size, last modify time). Is there any API that could help?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

Hope you will find your answer here:

The attributes of a file or directory can be obtained using the attributesOfItemAtPath method. This takes as arguments the path of the directory and an optional NSError object into which information about any errors will be placed (may be specified as NULL if this information is not required). The results are returned in the form of an NSDictionary dictionary object (for details of working with dictionary objects refer to Objective-C Dictionary Objects).

Some keys for this dictionary:


Example from above article:

(we can extract the creation date, file type and POSIX permissions for the /tmp directory using the following code excerpt)

NSFileManager *filemgr;
NSDictionary *attribs;

filemgr = [NSFileManager defaultManager];

attribs = [filemgr attributesOfItemAtPath: @"/tmp" error: NULL];

NSLog (@"Created on %@", [attribs objectForKey: NSFileCreationDate]);
NSLog (@"File type %@", [attribs objectForKey: NSFileType]);
NSLog (@"POSIX Permissions %@", [attribs objectForKey: NSFilePosixPermissions]);
share|improve this answer
add comment

The bleeding edge (may.13.2012) is using CFURL/NSURL properties:

id outName = nil;
NSString * key = NSURLNameKey;
NSError * outError = nil;

if (YES == [url getResourceValue:&value forKey:key error:&outError]) {
  NSString * name = outName;

Note: Make sure you request only what you need, and note that there are batch request methods/functions to minimize redundant requests. If using NSURL, you can use:

NSArray * keys = ...;
NSError * outError = nil;
NSDictionary * properties = [url resourceValuesForKeys:keys error:&outError];
share|improve this answer
add comment

You should look into the NSFileManager API. In particular the -attributesOfItemAtPath:error: method.

share|improve this answer
add comment

Your Answer


