iOS复制目录包括子目录 [英] iOS copy directories including subdirectories

查看:187
本文介绍了iOS复制目录包括子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用iOS文件夹名为temp,分配的子目录包含远程url下载的文件。现在我需要将temp目录及其所有内容复制到main文件夹(覆盖以前创建的现有文件夹)。我知道如何处理文件,但如何复制整个目录?谢谢

I am working with iOS document folder called "temp" that allocates subdirectories that contain files dowloaded from remote url. Now I need to copy "temp" directory and all its contents to "main" folder (overwrite existing that was previously created). I know how to handle files but how to copy whole directory? Thank you

推荐答案

您可以使用相同的 NSFileManager 和爱目录以及。例如:

You can use the same NSFileManager methods that you know and love for directories as well. For example:

if ([[NSFileManager defaultManager] fileExistsAtPath:pathToTempDirectoryInMain]) {
    [[NSFileManager defaultManager] removeItemAtPath:pathToTempDirectoryInMain error:nil];
}
NSError *copyError = nil;
if (![[NSFileManager defaultManager] copyItemAtPath:pathToTempDirectory toPath:pathToTempDirectoryInMain error:&copyError]) {
    NSLog(@"Error copying files: %@", [copyError localizedDescription]);
}

这篇关于iOS复制目录包括子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆