objective c - Zip the doc file in ios and save in to document directory -


i save doc file zip file in document directory , when user chooses can attach in email. have created zip file when want open again creates zipfile, zip.cpgz instead of testing.zip .

here code creating zip file

nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0];  nsarray *filepathsarray = [[nsfilemanager defaultmanager] subpathsofdirectoryatpath:documentsdirectory  error:nil];  int index =0; (nsstring *item in filepathsarray){     if ([[item pathextension] isequaltostring:@"doc"])     {        nsstring *filepath = [documentsdirectory stringbyappendingpathcomponent:[filepathsarray objectatindex:index]];         //nsstring *filename=[stringpath1 stringbyappendingpathcomponent:@"console.doc"];          nsstring *stringpath=[documentsdirectory stringbyappendingpathcomponent:[@"testing" stringbyappendingformat:@".zip"]];          zipfile *zipfile = [[zipfile alloc]initwithfilename:stringpath mode:zipfilemodecreate];           zipwritestream *stream= [zipfile writefileinzipwithname:@"doc" compressionlevel:zipcompressionlevelbest];         nsdata *data = [nsdata datawithcontentsoffile:filepath];         [stream writedata:data];         [stream finishedwriting];      } } 

you must use ssziparchive

an utility class zipping , unzipping files ios

example provided:-

// unzipping nsstring *zippath = @"path_to_your_zip_file"; nsstring *destinationpath = @"path_to_the_folder_where_you_want_it_unzipped"; [ssziparchive unzipfileatpath:zippath todestination:destinationpath];       // zipping     nsstring *zippedpath = @"path_where_you_want_the_file_created";     nsarray *inputpaths = [nsarray arraywithobjects:                            [[nsbundle mainbundle] pathforresource:@"photo1" oftype:@"jpg"],                            [[nsbundle mainbundle] pathforresource:@"photo2" oftype:@"jpg"]                            nil];     [ssziparchive createzipfileatpath:zippedpath withfilesatpaths:inputpaths]; 

Comments