2013-05-09 180 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參數是作爲結果所需的結果壓縮文件的路徑。

相關問題