Ich möchte eine zip
Datei erstellen, die mehrere Dokumente enthält, Dokumente stammen aus meinem Dokumentenverzeichnis.Wie Sie mehrere Dokumente in einer Zip-Datei in iOS hinzufügen?
BOOL isDir=NO;
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *subpaths;
for(int i=0; i<[arrdocument count]; i++)
{
NSString *toCompress = [arrdocument objectAtIndex:i];
NSString *pathToCompress = [documentsDirectory stringByAppendingPathComponent:toCompress];
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 *zipFilePath = [documentsDirectory stringByAppendingPathComponent:@"myZipFileName2.zip"];
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];
}
}
Aber wenn ich an der zip
Datei aussehen zeigt es nur ein Dokument in der ZIP-Datei?
By the way, sollten Sie auch CloseZipFile2 anrufen, wenn Sie mit fertig sind die Datei. In Ihrem Fall müssen Sie dies tun, nachdem Sie die Datei vor dem Ende der Schleife hinzugefügt haben. –
Sir gibt es keine Option zum Anhängen in ZipArchive. –
Ich habe "arrdocument", Array von Dateien, die ich in zip-Datei hinzufügen möchte. vorschlagen, wenn Sie die andere Möglichkeit haben, es zu tun. –