zip

zip, zip all documents

August 18, 2013   ·   0 Comments

-(void) zipDocument{
    
    BOOL isDir=YES;
    
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    NSArray *subpaths;
    
    NSString *toCompress = @"";//dirToZip_OR_fileNameToZip";
    NSString *pathToCompress = [documentsDirectory stringByAppendingPathComponent:toCompress];
    NSLog(@"dir: %@",pathToCompress);
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:pathToCompress isDirectory:&isDir] && isDir){
        subpaths = [fileManager subpathsAtPath:pathToCompress];
    } else if ([fileManager fileExistsAtPath:pathToCompress]) {
        subpaths = [NSArray arrayWithObject:pathToCompress];
    }
 
    
    NSString *phonenumber = [[NSUserDefaults standardUserDefaults]
                            stringForKey:@"phonenumber"];
   // if(phonenumber==nil || phonenumber.length<=0) return;
    
    FileZipName=[self GetDateToString];
    FileZipName=[NSString stringWithFormat:@"%@_%@.zip",phonenumber,FileZipName];
    
    
    NSString *zipFilePath = [documentsDirectory stringByAppendingPathComponent:FileZipName];
    
    ZipArchive *za = [[ZipArchive alloc] init];
    [za CreateZipFile2:zipFilePath];
    
        
    if (isDir) {
        for(NSString *path in subpaths){
            NSString *fullPath = [pathToCompress stringByAppendingPathComponent:path];
            if([fileManager fileExistsAtPath:fullPath isDirectory:&isDir] && !isDir){
                [za addFileToZip:fullPath newname:path];
            }
        }
    } else {
        [za addFileToZip:pathToCompress newname:toCompress];
    }
    
    
    //BOOL successCompressing =
    [za CloseZipFile2];
    
}

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
iOS Tutorial9

Amazon

adsbygoogle

Recent Posts

Categories

Amazon