iOS - 拷貝resource資原始檔夾
#pragma mark -- 拷貝資源
-(void)zip{ NSString *docPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; //Document目錄 NSString *dataPath=[NSString stringWithFormat:@"%@/Data/Raw",[[NSBundle mainBundle] resourcePath]]; // 專案包中的路徑 NSFileManager* fileManager = [NSFileManager defaultManager]; // 先刪除ClientRes資料夾 NSString * documentDir = [docPath stringByAppendingPathComponent:@"/ClientRes"]; BOOL isDir = NO; BOOL existed = [fileManager fileExistsAtPath:documentDir isDirectory:&isDir];
if ( !(isDir == YES && existed == YES) ) { KkLog(@"ClientRes不存在"); }else { BOOL s=[[NSFileManager defaultManager] removeItemAtPath:documentDir error:nil]; if (s) { KkLog(@"刪除成功"); }else{ KkLog(@"刪除失敗"); } }
//下面是對該檔案進行制定路徑的儲存[fileManager createDirectoryAtPath:dataPath withIntermediateDirectories:YES attributes:nil error:nil]; //取得一個目錄下得所有檔名 NSArray *filels = [fileManager subpathsAtPath:dataPath ];
for(int i = 0;i < filels.count;i++) { BOOL isdir = NO; NSString * curpath = [filels objectAtIndex:i]; NSString * npath = [NSString stringWithFormat:@"%@/%@",dataPath,curpath]; NSString *copyPath = [NSString stringWithFormat:@"%@/%@",docPath,curpath];
KkLog(@"i ---- %d curpath ---- %@ npath ---- %@",i,curpath,npath);
[fileManager fileExistsAtPath:npath isDirectory:&isdir];
if (isdir && YES)
{
[self createFolder:copyPath];
}
else
{
if(![self copyMissingFile:npath toPath:copyPath]){
[fileManager copyItemAtPath:npath toPath:copyPath error:nil];
}
}
}
}`
/**
- @brief 建立資料夾
- @param createDir 建立資料夾路徑
*/
- (void)createFolder:(NSString *)createDir { BOOL isDir = NO; NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL existed = [fileManager fileExistsAtPath:createDir isDirectory:&isDir]; if ( !(isDir == YES && existed == YES) ) { [fileManager createDirectoryAtPath:createDir withIntermediateDirectories:YES attributes:nil error:nil]; }else { NSLog(@"FileDir is exists."); } }
/**
- @brief 把Resource資料夾下的save1.dat拷貝到沙盒
- @param sourcePath Resource檔案路徑
- @param toPath 把檔案拷貝到XXX資料夾
- @return BOOL
*/
- (BOOL)copyMissingFile:(NSString *)sourcePath toPath:(NSString *)toPath { [self deletDocumentsFile:toPath]; BOOL retVal = YES; // If the file already exists, we'll return success… NSString * finalLocation = [toPath stringByAppendingPathComponent:[sourcePath lastPathComponent]]; if (![[NSFileManager defaultManager] fileExistsAtPath:finalLocation]) { retVal = [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:finalLocation error:NULL]; } return retVal; }
相關文章
- iOS深拷貝和淺拷貝iOS
- iOS開發-深拷貝&淺拷貝iOS
- xcopy 實現批處理拷貝檔案或資料夾
- 深究cp拷貝資料夾時`/`的用法
- 淺拷貝和深拷貝 iOS 的copy 以及 mutablecopyiOS
- IOS學習之淺析深拷貝與淺拷貝iOS
- Mac拷貝/複製資料夾路徑快捷鍵Mac
- IOCP 檔案拷貝
- ubuntu拷貝資料夾到另外一個資料夾下,如何寫shell命令:Ubuntu
- ios 深淺拷貝學習iOS
- iOS深淺拷貝小結iOS
- IO流-檔案拷貝
- 檔案內容拷貝
- vue深拷貝淺拷貝Vue
- python 指標拷貝,淺拷貝和深拷貝Python指標
- js資料型別賦值,淺拷貝,深拷貝JS資料型別賦值
- Golang命令列拷貝檔案Golang命令列
- iOS 圖文並茂的帶你瞭解深拷貝與淺拷貝iOS
- 一文搞懂Java引用拷貝、淺拷貝、深拷貝Java
- jquery之物件拷貝深拷貝淺拷貝案例講解jQuery物件
- C++拷貝建構函式(深拷貝,淺拷貝)C++函式
- JS深拷貝與淺拷貝JS
- Java深拷貝和淺拷貝Java
- 物件深拷貝和淺拷貝物件
- javascript 淺拷貝VS深拷貝JavaScript
- JavaScript 深度拷貝和淺拷貝JavaScript
- JavaScript深拷貝和淺拷貝JavaScript
- js 淺拷貝和深拷貝JS
- js 深拷貝和淺拷貝JS
- JavaScript淺拷貝和深拷貝JavaScript
- js深拷貝和淺拷貝JS
- js 深拷貝 vs 淺拷貝JS
- 資料檔案拷貝檔案頭驗證錯誤
- 淺談深拷貝與淺拷貝?深拷貝幾種方法。
- C++淺拷貝和深拷貝C++
- 深拷貝、淺拷貝與Cloneable介面
- 賦值、淺拷貝與深拷貝賦值
- 實現物件淺拷貝、深拷貝物件