У меня есть этот код и сообщение об ошибке с текстом:IOS: Перемещение файлов в каталог
ERROR: Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x145b5a60 {NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/Application/E905FE5A-C39B-41F0-8BC7-FC58CC3F4306/Library/Caches/2D0404EE-746C-4C1E-98F3-42FFE485BE3B.zip, NSUserStringVariant=( Move ), 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 "The operation couldn’t be completed. No such file or directory"}
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 атрибуты: nil error: & error];' бесполезно, потому что '' Files ''не является файлом е путь. Кроме того, вы пробовали регистрировать значение 'fromPath' до операции? –
Произошла такая же ошибка –