【问题标题】:iphone copying folder from bundle to documentsiphone将文件夹从捆绑包复制到文档
【发布时间】:2011-05-02 12:04:20
【问题描述】:

我很难让它发挥作用。我正在尝试将一个文件夹从我的包复制到文档目录。

我要查找的文件夹在这里:

...app/Resources/12/(一堆jpg)

NSString *myPath = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"12"];
NSLog(@"%@",myPath);/// returns "..../MyApp.app/12"

NSArray *arrayOf12s = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:myPath error:nil];

NSLog(@"%@",arrayOf12s);     ////always returns NULL

【问题讨论】:

    标签: iphone nsfilemanager nsbundle


    【解决方案1】:

    在 -contentsOfDirectoryAtPath:error: call 中使用 NSError 参数怎么样?

    NSString *myPath = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"12"];
    NSLog(@"%@",myPath);/// returns "..../MyApp/12"
    
    NSError *error = nil;
    NSArray *arrayOf12s = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:resourceDBFolderPath error:&error];
    
    if (error)
       NSLog(@"Error: %@", [error localizedDescription]);
    
    NSLog(@"%@",arrayOf12s);     ////always returns NULL
    

    它可能会对原因有所启发......

    【讨论】:

    • 它给出的只是:错误:操作无法完成。 (可可错误 260。)
    • 'resourceDBFolderPath' 设置为什么?
    • 另外,你见过这个stackoverflow.com/questions/418680/…>吗?它可能有助于将整个目录包含到您的应用程序包中 - 而不仅仅是目录的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 2016-03-24
    • 2012-04-07
    • 1970-01-01
    • 2011-03-15
    相关资源
    最近更新 更多