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 distin开发者_运维百科guish between files and folders in a directory.
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
CFURLURLEnumerator
will do this and prefetch properties you specify. if performance/time is a concern, then you should favor a lower level approach such as this. higher level apis may fetch more properties from the filesystem than you are interested in - which can add a lot of time to your crawl.
精彩评论