【问题标题】:Copying plist file to custom folder in ApplicationSupport (Objective-C)将 plist 文件复制到 ApplicationSupport (Objective-C) 中的自定义文件夹
【发布时间】:2010-12-16 13:38:21
【问题描述】:

我有这段代码,它将一个 plist 文件复制到用户文件夹中的 ApplicationSupport 目录。

NSString *resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:kAutonumberPlist];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);

    NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:kAutonumberPlist];
    NSFileManager *fileManager = [NSFileManager defaultManager];

    if (![fileManager fileExistsAtPath:dataPath]) {
        [fileManager copyItemAtPath:resourcePath toPath:dataPath error:nil];
    }

我该如何更改它,而不是将文件复制到 ~User/Library/ApplicationSupport 中,而是将其复制到 ~User/Library/ApplicationSupport/AnotherFolder。顺便说一句,“另一个文件夹”已经存在。

谢谢!

【问题讨论】:

    标签: objective-c plist directory copying


    【解决方案1】:

    您已经在使用 stringByAppendingPathComponent - 您可以再次使用它。

    例如:

    NSString *dataPath = [[[paths objectAtIndex:0] 
                            stringByAppendingPathComponent: @"AnotherFolder"]
                            stringByAppendingPathComponent: kAutonumberPlist];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 2019-05-03
      • 1970-01-01
      • 2020-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多