【发布时间】:2015-09-25 15:44:46
【问题描述】:
我有这个代码和文本错误:
错误:错误域 = NSCocoaErrorDomain 代码 = 4“操作无法完成。(可可错误 4。)” UserInfo = 0x145b5a60 {NSSourceFilePathErrorKey = /private/var/mobile/Containers/Data/Application/E905FE5A-C39B -41F0-8BC7-FC58CC3F4306/库/缓存/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/ Containers/Data/Application/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);
}
}
真的不明白为什么会这样
【问题讨论】:
-
[fileManager createDirectoryAtPath:dictionaryName withIntermediateDirectories:NO attributes:nil error:&error];行没有用,因为"Files"不是文件路径。另外,您是否尝试在操作前记录fromPath的值?
标签: ios nsfilemanager file-manager