2009-11-14 24 views
0

我有這段代碼,它將plist文件複製到users文件夾中的ApplicationSupport目錄。將Plist文件複製到ApplicationSupport(Objective-C)中的自定義文件夾中

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

如何CA改變它,這樣,而不是將文件複製到〜用戶/庫/ ApplicationSupport,將其複製到〜用戶/庫/ ApplicationSupport/AnotherFolder。 「AnotherFolder」已經存在了。

謝謝!

回答

3

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

例如:

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

謝謝您的幫助! – Michael

相關問題