如何使用NSDocumentDirectory
压缩ZipArchive
的子目录?
答案 0 :(得分:0)
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");