开发者

Copying plist file to custom folder in ApplicationSupport (Objective-C)

I have this piece of code, which copies a plist file to the ApplicationSupport directory in the users folder.

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];
    }

How ca I change it so that instead of copying the file into ~User/Library/ApplicationSupport, it will copy it into ~User/Library/ApplicationSupport/AnotherFolder. The "AnotherFolder" alrea开发者_Python百科dy exists by the way.

Thank you!


You are already using stringByAppendingPathComponent - you could just use it again.

For example:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜