【发布时间】:2015-05-21 06:57:02
【问题描述】:
如何将文件夹从一个位置移动到另一个位置。 我在库/数据中有一个文件夹,我需要移动到文档/数据。有可能吗?
提前致谢
【问题讨论】:
-
谢谢老哥,解决了我的问题。
如何将文件夹从一个位置移动到另一个位置。 我在库/数据中有一个文件夹,我需要移动到文档/数据。有可能吗?
提前致谢
【问题讨论】:
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;
// 如果要添加任何子路径到目标文件夹,请添加 else 提交以下行
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
}
【讨论】: