0

NSDocumentDirectoryを使用してサブディレクトリを圧縮するにはどうすればよいZipArchiveですか?

4

1 に答える 1

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");
于 2013-01-24T12:20:32.730 に答える