I try to move the file folder to a temporary folder, but I always get the same error: The operation could not be completed. (Cocoa error 516.)
This is the code, do you see anything strange? Thanks in advance.
NSString* newPath=[[self getDocumentsDirectory] stringByAppendingPathComponent:@"algo_bueno"];
NSLog(@"newPath %@", newPath);
if ([[NSFileManager defaultManager] fileExistsAtPath:newPath]) {
NSLog(@"newPath already exists.");
} else {
NSError *error;
if ([[NSFileManager defaultManager] createDirectoryAtPath:newPath withIntermediateDirectories:YES attributes:nil error:&error]) {
NSLog(@"newPath created.");
} else {
NSLog(@"Unable to create directory: %@", error.localizedDescription);
return;
}
}
NSError *error;
NSString* myString=[NSString stringWithFormat:@"Probando..."];
NSString* filePath=[newPath stringByAppendingPathComponent:@"myfile.txt"];
if ([myString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error]) {
NSLog(@"File created.");
} else {
NSLog(@"Failed creating file. %@", error.localizedDescription);
return;
}
NSString *tmpDir = NSTemporaryDirectory();
NSLog(@"temporary directory, %@", tmpDir);
if ([[NSFileManager defaultManager] moveItemAtPath:newPath toPath:tmpDir error:&error]) {
NSLog(@"Movido a temp correctamente");
} else {
NSLog(@"Failed moving to temp. %@", error.localizedDescription);
}
source
share