在 iOS 中,我想使用开关将图像移动到特定位置,当开关打开时,它会将图像移动到我指定的位置,当它关闭时,它将移动到它来自的位置。
最佳答案
您可以使用以下函数将所有图像移动
到新的路径
。
您只需要传递
DirectoryPath
Old
和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;
}
}
}
关于ios - 如何将 iOS 中的图像从一个目录移动到另一个目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27561356/