ios下移动文件方法汇总下移动文件方法汇总
这段objective c代码用于移动指定路径下的文件
代码如下:
if ([fileManager copyItemAtPath:@”FilePath1″
toPath:@”FilePath2″ error:NULL]) {
NSLog(@”Copied successfully”);
}
方法二方法二:
使用 NSFileManager:
让您的文档的路径和您的缓存路径。遍历所有的文件,并将它们移动使用 NSFileManager
代码如下:
– (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);
}
}
}
方法三方法三:
FCFileManager 是一个构建在 NSFileManager 之上的 iOS 文件管理工具,简化了文件管理。它提供了许多静态方法,用于执
行最常用的操作用几行代码。它的工作原理是默认的文件目录,允许使用相对路径,但它可以在任何其他目录中轻松工作。
Move file:
代码如下:
[FCFileManager moveItemAtPath:@”test.txt” toPath:@”tests/test.txt”];
Remove file:
代码如下:
//remove file at the specified path
[FCFileManager removeItemAtPath:@”test.txt”];
以上所述上就是本文的全部内容了,希望大家能够喜欢。
您可能感兴趣的文章您可能感兴趣的文章:IOS开发教程之put上传文件的服务器的配置及实例分享nagios 分发文件实现代码ios系统下删除文件的代
码ios实现文件对比的方法IOS检测指定路径的文件是否存在
评论0
最新资源