2013-05-09 125 views
0

我喜欢使用ZipKit压缩文件夹?如何使用ZipKit压缩文件夹?

我似乎无法找到ZipKit库中函数使用的良好文档。 有人可以解释文件夹压缩的方法吗?

ZKFileArchive *archive = [ZKFileArchive archiveWithArchivePath:filePath]; 
[archive deflateDirectory:param1 relativeToPath:param2 usingResourceFork:NO]; 

需要什么参数1和参数传递?我不明白这里的函数调用?

如果有人能为此发布一个示例,那将会很棒吗?

谢谢!

回答

2

Looking at the answer in this related question,这是一个很好的例子。

您的param1是要存档的文件夹(其路径),相对路径可能是父文件夹。

NSString *zipFilePath = @"/Documents/zipped.zip"; 
ZKFileArchive *archive = [ZKFileArchive archiveWithArchivePath:zipFilePath]; 
NSInteger result = [archive deflateDirectory:@"/Documents/myfolder" relativeToPath:@"/Documents" usingResourceFork:NO]; 

如果ZipKit有更好的文档比the limited info it has这将是很好。

+0

让它工作.. thanx! – 2013-05-09 21:05:03

0

我使用ZipKitNSFileManager创建了以下类别方法。

- (BOOL)zipContentsOfDirectoryAtPath:(NSString *)directory toPath:(NSString *)filename recursive:(BOOL)recursive { 
    // If there is already a file at the destination, delete it 
    if ([self fileExistsAtPath:filename]) { 
     [self removeItemAtPath:filename error:nil]; 
    } 

    @try { 
     ZKFileArchive *archive = [ZKFileArchive archiveWithArchivePath:filename]; 
     NSInteger result = [archive deflateDirectory:directory relativeToPath:directory usingResourceFork:NO]; 

     return result == zkSucceeded; 
    } 
    @catch (NSException *exception) { 
     if ([self fileExistsAtPath:filename]) { 
      [self removeItemAtPath:filename error:nil]; 
     } 
    } 

    return NO; 
} 

directory参数是您要的拉上目录(及其内容)的路径。 filename参数是作为结果所需的结果压缩文件的路径。