【问题标题】:ios - Move folders from Library folder to Documents folderios - 将文件夹从库文件夹移动到文档文件夹
【发布时间】:2015-05-21 06:57:02
【问题描述】:

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

提前致谢

【问题讨论】:

标签: ios iphone


【解决方案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;

// 如果要添加任何子路径到目标文件夹,请添加 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
}

【讨论】:

    猜你喜欢
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多