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 是一個構(gòu)建在 NSFileManager 之上的 iOS 文件管理工具,簡化了文件管理。它提供了許多靜態(tài)方法,用于執(zhí)行最常用的操作用幾行代碼。它的工作原理是默認的文件目錄,允許使用相對路徑,但它可以在任何其他目錄中輕松工作。
Move file:
[FCFileManager moveItemAtPath:@"test.txt" toPath:@"tests/test.txt"];
Remove file:
//remove file at the specified path
[FCFileManager removeItemAtPath:@"test.txt"];
以上所述上就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
iOS逆向工程使用LLDB的USB連接調(diào)試第三方App
這篇文章主要介紹了iOS逆向工程使用LLDB的USB連接調(diào)試第三方App,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
iOS開發(fā)之image圖片壓縮及壓縮成指定大小的兩種方法
這篇文章主要介紹了iOS開發(fā)之image圖片壓縮及壓縮成指定大小的兩種方法,需要的朋友可以參考下2017-11-11
iOS App中實現(xiàn)播放音效和音樂功能的簡單示例
這篇文章主要介紹了iOS App中實現(xiàn)播放音效和音樂功能的簡單示例,示例代碼為傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-03-03
iOS - UIButton(UIEdgeInsets)/設(shè)置button上的文字和圖片上下垂直居中對齊
這篇文章主要介紹了iOS - UIButton(UIEdgeInsets)/設(shè)置button上的文字和圖片上下垂直居中對齊的相關(guān)資料,需要的朋友可以參考下2015-09-09
iOS 原生實現(xiàn)掃描二維碼和條形碼功能限制掃描區(qū)域
這篇文章主要介紹了iOS 原生實現(xiàn)掃描二維碼和條形碼功能限制掃描區(qū)域,需要的朋友可以參考下2017-03-03

