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í)行最常用的操作用幾行代碼。它的工作原理是默認(rèn)的文件目錄,允許使用相對路徑,但它可以在任何其他目錄中輕松工作。
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 開發(fā)之網(wǎng)絡(luò)圖片輪播圖的實(shí)現(xiàn)
這篇文章主要介紹了IOS 開發(fā)之網(wǎng)絡(luò)圖片輪播圖的實(shí)現(xiàn)的相關(guān)資料,希望通過此文大家能夠掌握輪播圖的實(shí)現(xiàn),需要的朋友可以參考下2017-09-09IOS Xcode調(diào)試常用命令和斷點(diǎn)整理
這篇文章主要介紹了IOS Xcode調(diào)試常用命令和斷點(diǎn)整理的相關(guān)資料,這里對IOS Xcode調(diào)試常用命令進(jìn)行了總結(jié),需要的朋友可以參考下2016-12-12MAUI模仿iOS多任務(wù)切換卡片滑動的交互實(shí)現(xiàn)代碼
這篇文章主要介紹了[MAUI]模仿iOS多任務(wù)切換卡片滑動的交互實(shí)現(xiàn),使用.NET MAU實(shí)現(xiàn)跨平臺支持,本項(xiàng)目可運(yùn)行于Android、iOS平臺,需要的朋友可以參考下2023-05-05iOS利用攝像頭獲取環(huán)境光感參數(shù)的方法
本篇文章主要介紹了iOS利用攝像頭獲取環(huán)境光感參數(shù)的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11