ios - 如何将 iOS 中的图像从一个目录移动到另一个目录?

标签 ios objective-c filepath

在 iOS 中,我想使用开关将图像移动到特定位置,当开关打开时,它会将图像移动到我指定的位置,当它关闭时,它将移动到它来自的位置。

最佳答案

您可以使用以下函数将所有图像移动到新的路径

您只需要传递DirectoryPath OldNew

- (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/

相关文章:

iOS 不止一个 Unwind Segues on a Button

iphone - iOS 6 模拟器中的 ABAddresBook 权限

ios - 将模态视图放在 View 上并使背景变灰

c# - F#:从 ViewController 中的 Storyboard 访问 UI 元素?

ios - SQLITE:INTERSECT/UNION 选择结果和法线数组

ios - 如何使用 Web 服务搜索多个单词

iphone - 如何更改 UITextField clearButton 的颜色?

c# - 获取 wcf 服务程序集中文件的路径

Windows 7 自定义搜索提供程序的安全问题

java - 如何用 "\\"分割字符串