I'm using ZipArchive to unzip but its unzipping the contents of the zip to a subdirectory of my documents named after the zip file instead of directly into my documents folder. Does anyone know what I can change to make sure its saves to the directory that I want?
-(void) unZipUpdateArchiveAtPath: (NSString *)zipPath {
NSLog(@"UNZIP Update PATH: %@", zipPath);
ZipArchive *zipArchive = [[ZipArchive alloc] init];
if ([zipArchive UnzipOpenFile:zipPath])
{
if ([zipArchive UnzipFileTo:[self documentDirectory] overWrite:YES])
{
NSLog(@"Archive unzip success");
[zipArchive UnzipCloseFile];
}
else
{
NSLog(@"Failure to unzip archive");
}
}
else
{
NSLog(@"Failure to open archive");
}
}
#pragma mark - Application's Documents directory
-(NSString *)documentDirectory
{
NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentDirectory = [documentDirectories objectAtIndex:0];
NSLog(@"docDirectory IS %@", documentDirectory);
return documentDirectory;
}
You need to append your custom path to your documents directory.
[zipArchive UnzipFileTo:[[self documentDirectory] stringByAppendingPathComponent:@"My folder"] overWrite:YES];
来源:https://stackoverflow.com/questions/10725176/ziparchive-unzip-to-document-folder-on-ios