views:

136

answers:

1

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" already exists by the way.

Thank you!

+3  A: 

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

For example:

NSString *dataPath = [[[paths objectAtIndex:0] 
                        stringByAppendingPathComponent: @"AnotherFolder"]
                        stringByAppendingPathComponent: kAutonumberPlist];
JimG
Thank you for your help!
Michael