ios - 将文件夹从Library文件夹移动到Documents文件夹

时间:2015-05-21 06:57:02

标签: ios iphone

如何将文件夹从一个位置移动到另一个位置。 我在Library / data中有一个文件夹,我需要移动到Documents / data。有可能吗?

提前致谢

1 个答案:

答案 0 :(得分:1)

NSArray *pathDirectory= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *toPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"toFolderName"];

如果要从文档目录中移动文件,请使用以下行

NSString *fromPath=[[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"fromFolderName"];

如果您想从捆绑中移动,请使用以下

NSString *frompath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"fileType"];

NSError *Error;

//如果要将任何子路径添加到目标文件夹,请在行

后添加其他提交
 NSString *toPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"toSub"];

//删除您所在位置的文件'重新复制

NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:toPath error:NULL];

if([[NSFileManager defaultManager]copyItemAtPath:from toPath:toPath error:&Error]==NO){
 // do somthing on succes if you want
}
相关问题