小编Bre*_*ner的帖子

NSFileManager copyItemAtPath会抱怨确实存在的不存在的文件

我正在尝试复制文件[[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] …

file-io objective-c nsfilemanager

4
推荐指数
1
解决办法
2583
查看次数

标签 统计

file-io ×1

nsfilemanager ×1

objective-c ×1