2009-11-14 4 views
0

plist 파일을 사용자 폴더의 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

관련 문제