【问题标题】:iPhone SDK Xcode - How to get all the filenames in the documents diriPhone SDK Xcode - 如何获取文档目录中的所有文件名
【发布时间】:2011-10-27 05:02:57
【问题描述】:

我想获取应用程序的documents 文件夹中的所有文件名,并将它们放在NSMutableArray 中。不多也不少。

【问题讨论】:

    标签: ios nsmutablearray nsarray nsdocumentdirectory


    【解决方案1】:

    NSFileManager中有一个方便的方法:

    NSFileManager *fileManager = [[NSFileManager alloc] init];
    NSArray *files = [fileManager contentsOfDirectoryAtPath:documentsDirectory 
                                                      error:nil];
    ...
    [fileManager release];
    

    从 ARC 开始,您当然可以放弃发布声明。

    【讨论】:

    • 您应该使用[[NSFileManager alloc] init] 而不是[NSFileManager defaultManager],它返回一个线程安全的NSFileManager 实例。
    • 这段代码的 sn-p 将被复制和粘贴多年 - 它可能是最新的。
    猜你喜欢
    • 2016-03-07
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多