Search code examples
iphoneobjective-ciosxcodensfilemanager

Getting more details from NSFileManager contentsOfDirectoryAtPath


Is there a way to get more details (size,date created,etc) about a specific item when using contentsOfDirectoryAtPath or a similar method?

I really need to be able to distinguish between files and folders in a directory.


Solution

  • You'll want to look at the following method from NSFileManager:

    - (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error
    

    The dictionary of attributes returned contains many keys, but the NSFileType key will help you determine whether the path points to an NSFileTypeDirectory (directory) or a NSFileTypeRegular (regular file). The following keys may also be of interest:

    NSFileSize
    NSFileCreationDate
    NSFileModificationDate