ZipArchive 用法
2014-04-14 20:31
309 查看
ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ;
NSString* image1 = [documentpath stringByAppendingString:@"/image1.jpg"] ;
NSString* image2 = [documentpath stringByAppendingString:@"/image2.jpg"] ;
BOOL ret = [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:image1 newname:@"image1.jpg"];
ret = [zip addFileToZip:image2 newname:@"image2.jpg"];
if( ![zip CloseZipFile2] )
{
l_zipfile = @"";
}
[zip release];
2. 解压缩:
[cpp] view
plaincopy
ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ;
NSString* unzipto = [documentpath stringByAppendingString:@"/test"] ;
if( [zip UnzipOpenFile:l_zipfile] )
{
BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
if( NO==ret )
{
}
[zip UnzipCloseFile];
}
[zip release];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ;
NSString* image1 = [documentpath stringByAppendingString:@"/image1.jpg"] ;
NSString* image2 = [documentpath stringByAppendingString:@"/image2.jpg"] ;
BOOL ret = [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:image1 newname:@"image1.jpg"];
ret = [zip addFileToZip:image2 newname:@"image2.jpg"];
if( ![zip CloseZipFile2] )
{
l_zipfile = @"";
}
[zip release];
2. 解压缩:
[cpp] view
plaincopy
ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ;
NSString* unzipto = [documentpath stringByAppendingString:@"/test"] ;
if( [zip UnzipOpenFile:l_zipfile] )
{
BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
if( NO==ret )
{
}
[zip UnzipCloseFile];
}
[zip release];
相关文章推荐
- ubuntu下安装VNC远程桌面的详细步骤
- Ubuntu11.10下安装sqldeveloper
- ubuntu下安装谷歌拼音输入法(ibus)
- ubuntu安装goldendict翻译工具,很好用!
- Kvm教程
- poj 1753 Flip Game
- NYOJ 824 Greedy Mouse
- windows创建SVN服务器之三---快速搭建版本控制环境
- 嵌入式web服务器
- MinGW简介
- CentOS 6.4 配置 KVM虚拟机笔记(快速简单方便安装)
- CentOS 6.4 快速安装Nginx笔记
- 《卓越程序员密码》
- Java 正则表达式
- php 当前时间: 用php实现将当前日期时间
- 日常开发工具
- 如何查看controlfile 里的MAXDATAFILES
- 经典SQL(1) ---列转行
- 使用LinkedHashMap实现的LRU算法
- Ubuntu 搭建 NFS服务提供给 SC2440或SC6410开发板使用【要点整理】