2011-04-20 5 views
0

내 문서 폴더에있는 폴더에 파일이 있습니다. 다른 이름으로 다른 폴더에 파일의 사본을 만들고 싶습니다. 코드 나는 사용하고있다파일 관리자를 사용하여 파일 관리자를 사용하여 파일 사본을 만드는 것이 Mac 응용 프로그램에서 작동하지 않습니다

NSFileManager *fileManager = [[NSFileManager alloc] init]; 
NSString * filePath = [NSHomeDirectory() stringByAppendingPathComponent: 
    [NSString stringWithFormat:@"Documents/test/test1/%@%@%@",str,currentaudioTobPlayed,@".mp3"]]; 
NSString * filePath2 = [NSHomeDirectory() stringByAppendingPathComponent: 
    [NSString stringWithFormat:@"Documents/test/test1/"]]; 

NSLog(@"filePat %@",filePath); 
NSLog(@"filePath2 %@",filePath2); 
NSLog(@"filePath2 %@",fileManager); 

[fileManager copyItemAtPath:filePath toPath:filePath2 error:NULL]; 
[fileManager release]; 

그러나이 코드는 작동하지 않습니다. 제발 도와주세요!

+0

@Bavarious 고맙습니다! 그것이 효과가있었습니다. 만약 당신이 대답했다면, 나는 당신에게 투표했을 것입니다. 어쨌든 고맙습니다. – Swastik

+0

저는 의견을 본격적인 대답으로 옮겼습니다. –

답변

0

에서 :

NSString * filePath2 = [NSHomeDirectory() stringByAppendingPathComponent: 
    [NSString stringWithFormat:@"Documents/test/test1/"]]; 

는 대상 파일 이름을 지정하지 않는 : ~/문서/시험/TEST1은 디렉토리입니다.

대신이 작업을 수행 할 수 있습니다 :

NSString *sourceName = [NSString stringWithFormat:@"%@%@.mp3", 
    str, currentaudioTobPlayed]; 

// Choose the destination file name 
NSString *destName = [NSString stringWithFormat:@"Copy of %@", sourceName]; 

NSString * filePath = [NSHomeDirectory() stringByAppendingPathComponent: 
[NSString stringWithFormat:@"Documents/test/test1/%@", sourceName]]; 

NSString * filePath2 = [NSHomeDirectory() stringByAppendingPathComponent: 
    [NSString stringWithFormat:@"Documents/test/test1/%@", destName]]; 
// Replace Documents/test/test1 with another directory under home, 
// or replace the whole string with an entirely different directory 
+0

@ 스와 스틱, 귀하의 질문에 대한 가시성을 가져 오는 정중 한 방법은 [현상금 게시] (http://stackoverflow.com/faq#bounty)입니다. – sarnold

관련 문제