源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

ios下移动文件方法汇总

  • 时间:2022-09-01 09:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:ios下移动文件方法汇总
这段objective c代码用于移动指定路径下的文件
[u]复制代码[/u] 代码如下:
if ([fileManager copyItemAtPath:@"FilePath1"   toPath:@"FilePath2"  error:NULL]) {      NSLog(@"Copied successfully");   }
[b]方法二[/b]: 使用 NSFileManager: 让您的文档的路径和您的缓存路径。遍历所有的文件,并将它们移动使用 NSFileManager
[u]复制代码[/u] 代码如下:
- (void) moveAllDocs {     NSFileManager *fileManager = [NSFileManager defaultManager];     NSError *error = nil;     NSString *sourceDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];     NSString *destinationDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];     NSArray *contents = [fileManager contentsOfDirectoryAtPath:sourceDirectory error:&error];     for(NSString *sourceFileName in contents) {         NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:sourceFileName];         NSString *destFile = [destinationDirectory stringByAppendingPathComponent:sourceFileName];         if(![fileManager moveItemAtPath:sourceFile toPath:destFile error:&error]) {             NSLog(@"Error: %@", error);         }     } }
[b]方法三[/b]: FCFileManager 是一个构建在 NSFileManager 之上的 iOS 文件管理工具,简化了文件管理。它提供了许多静态方法,用于执行最常用的操作用几行代码。它的工作原理是默认的文件目录,允许使用相对路径,但它可以在任何其他目录中轻松工作。 Move file:
[u]复制代码[/u] 代码如下:
[FCFileManager moveItemAtPath:@"test.txt" toPath:@"tests/test.txt"];
Remove file:
[u]复制代码[/u] 代码如下:
//remove file at the specified path [FCFileManager removeItemAtPath:@"test.txt"];
以上所述上就是本文的全部内容了,希望大家能够喜欢。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部