0
如何使用ZipArchive
壓縮NSDocumentDirectory
的子目錄?使用ZipArchive的NSDocumentDirectory中的Zip子目錄/子文件夾
如何使用ZipArchive
壓縮NSDocumentDirectory
的子目錄?使用ZipArchive的NSDocumentDirectory中的Zip子目錄/子文件夾
BOOL isDir=NO;
NSArray *subpaths;
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:dataPath isDirectory:&isDir] && isDir)
{
subpaths = [fileManager subpathsAtPath:dataPath];
}
NSString *archivePath = [dataPath stringByAppendingString:@".zip"];
ZipArchive *archiver = [[ZipArchive alloc] init];
[archiver CreateZipFile2:archivePath];
for(NSString *path in subpaths)
{
NSString *longPath = [dataPath stringByAppendingPathComponent:path];
if ([fileManager fileExistsAtPath:longPath isDirectory:&isDir] && !isDir)
{
[archiver addFileToZip:longPath newname:path];
}
}
BOOL successCompressing = [archiver CloseZipFile2];
if(successCompressing)
NSLog(@"Successfully Zipped");
else
NSLog(@"Fail");
[你有什麼試過](http://whathaveyoutried.com/) – rckoenes