【问题标题】:how to copy Diffrent type of files from document directory in ios如何从ios中的文档目录复制不同类型的文件
【发布时间】:2015-08-11 09:30:36
【问题描述】:

我想将文档目录中的所有类型的文件复制到ios中的另一个目录,

if ([fileManager fileExistsAtPath:txtPath] == YES) {
    [fileManager removeItemAtPath:txtPath error:&error];
}

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"txtFile" ofType:@"txt"];
[fileManager copyItemAtPath:resourcePath toPath:txtPath error:&error];

我使用此代码但它仅对特定类型的文件有帮助。

【问题讨论】:

标签: ios iphone directory


【解决方案1】:

在做了一些更改并从其他参考资料中找到后,我终于得到了答案,我发现这段代码非常适合我

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePathsArray1 = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:dataPath  error:nil];

【讨论】:

    【解决方案2】:

    检查以下代码以从目录中获取所有类型的文件

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSArray *filePaths = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];

    【讨论】:

      猜你喜欢
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      • 2018-11-30
      • 2013-02-02
      • 1970-01-01
      • 2011-08-14
      • 2020-06-02
      相关资源
      最近更新 更多