How to move images in iOS from one directory to another?

In iOS, I want to move images to a specific location using the switch when the switch is on it, and will move the image to the location you specify when it turns off, it will move to where it is from.

+5
source share
1 answer

You can use the following function to move all of your images for the new Path .

You need to pass just DirectoryPath Old and New

 - (void)moveFileFromFolder:(NSString *)oldFolderPath toFolder:(NSString *)newFolderPath { NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *fileNames = [fileManager contentsOfDirectoryAtPath:oldFolderPath error:nil]; for (NSString *fileName in fileNames) { NSString * oldFilePath = [oldFolderPath stringByAppendingString:fileName]; NSString * newFilePath = [newFolderPath stringByAppendingString:fileName]; NSError *error = nil; [fileManager moveItemAtPath:oldFilePath toPath:newFilePath error:&error]; if (error) { NSLog(@"error = %@", [error description]); return; } } } 
+4
source

Source: https://habr.com/ru/post/1209518/


All Articles