我有这段代码和错误的文字:
错误:错误域= NSCocoaErrorDomain代码= 4"操作无法完成。 (可可错误4。)" UserInfo = 0x145b5a60 {NSSourceFilePathErrorKey = / private / var / mobile / Containers / Data / Application / E905FE5A-C39B-41F0-8BC7-FC58CC3F4306 / Library / Caches / 2D0404EE-746C-4C1E-98F3-42FFE485BE3B.zip,NSUserStringVariant =( 移动 ),NSFilePath = / private / var / mobile / Containers / Data / Application / E905FE5A-C39B-41F0-8BC7-FC58CC3F4306 / Library / Caches / 2D0404EE-746C-4C1E-98F3-42FFE485BE3B.zip,NSDestinationFilePath = / var / mobile /容器/数据/应用程序/ E905FE5A-C39B-41F0-8BC7-FC58CC3F4306 / Documents / Files / temp.zip,NSUnderlyingError = 0x1457af70"操作无法完成。没有这样的文件或目录"}
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *pathDocumentDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dictionaryName = @"Files";
NSString *filesPath = [[pathDocumentDirectory objectAtIndex:0] stringByAppendingPathComponent:dictionaryName];
NSString *toPath = [filesPath stringByAppendingPathComponent:@"temp.zip"];
NSString *fromPath = downloadedItem.contentURL.path;
NSError *error = nil;
BOOL isDir = YES;
if([fileManager fileExistsAtPath:fromPath])
{
// Create PurchasedBooks directory
if (![fileManager fileExistsAtPath:dictionaryName isDirectory:&isDir]) {
[fileManager createDirectoryAtPath:dictionaryName withIntermediateDirectories:NO attributes:nil error:&error];
}
[[NSFileManager defaultManager]moveItemAtPath:fromPath toPath:toPath error:&error];
if (error) {
NSLog(@"ERROR: %@", error.description);
}
}
真的不明白为什么会发生这种情况
答案 0 :(得分:0)
添加错误检查:
[fileManager createDirectoryAtPath:dictionaryName withIntermediateDirectories:NO attributes:nil error:&error];