iOS - Resource 리소스 폴더 복사

2871 단어
#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; }

    좋은 웹페이지 즐겨찾기