开发者

Getting more details from NSFileManager contentsOfDirectoryAtPath

开发者 https://www.devze.com 2023-04-01 01:35 出处:网络
Is there a way to get more details (size,date created,etc) about a specific item when using contentsOfDirectoryAtPath or a similar method?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号