這是我的代碼。iphone:從文件目錄文件夾複製或移動文件
NSArray *pathSong = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *toPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"Songs"];
NSString *fromPath=[[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"abc"];
NSString *strdestination = [fromPath stringByAppendingPathComponent:@"sg.mp3"];
NSError *Error;
if([[NSFileManager defaultManager]fileExistsAtPath:strdestination]){
if([[NSFileManager defaultManager]copyItemAtPath:strdestination toPath:toPath error:&Error]==NO){
UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"copy" message:[NSString stringWithFormat:@"%@",Error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[Alert show];
}
else{
UIAlertView *Alert=[[UIAlertView alloc]initWithTitle:@"Not copy" message:[NSString stringWithFormat:@"%@",Error] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[Alert show];
}
}
我得到了錯誤的標誌:
錯誤域= NSCocoaErrorDominCode = 516 「的操作無法完成 (可可箭頭516)」 USERINFO = 0x681abf0
NSUnderlyingError = 0x681b920「操作無法完成 。文件存在」
abc文件夾沒有歌曲名稱「sg.mp3」,但我仍然收到文件存在錯誤。我不知道我犯了什麼錯誤?
你能在你的代碼中設置代碼標籤嗎? – BergP 2012-08-17 11:44:41
您正試圖將一個文件複製到另一個文件上? – FaddishWorm 2012-08-17 11:46:02
@ FaddishWorm:我想將一個文件複製到另一個文件夾。 – user1606762 2012-08-17 11:52:40