我正在尝试复制文件[[NSFileManager defaultManager] copyItemAtPath: toPath: error:]但它失败并出现以下错误:
4:文件不存在.
相关代码如下,文件确实存在且路径字符串正确,因为它是事先使用完全相同的文件路径字符串创建的.
NSFileManager* manager = [NSFileManager defaultManager];
NSError* error;
NSString* fileName = [Sound getFileName:Title];
NSString* oldDirectory = [NSString stringWithFormat:@"%@%@/", [settings stringForKey:@"downloadFolder"], authorFolder];
NSString* oldFile = [oldDirectory stringByAppendingFormat:@"%@.mp3", fileName];
NSString* newFile = [NSString stringWithFormat:@"%@/iTunes/iTunes Media/Automatically Add to iTunes/%@.mp3", [NSSearchPathForDirectoriesInDomains(NSMusicDirectory, NSUserDomainMask, YES) objectAtIndex:0], fileName];
BOOL result = [manager copyItemAtPath:oldFile toPath:newFile error:&error];
if (!result && error)
{
NSLog(oldFile);
NSLog(@"There was an error copying the file to the iTunes directory! %@", [error localizedDescription]);
}
Run Code Online (Sandbox Code Playgroud)
这不是确切的代码,但所有相关代码都应该在上面.如果我使用[manager fileExistsAtPath:oldFile] …