Added option to keep parent directory when compressing directory contents

This commit is contained in:
Riley Testut
2014-12-21 18:02:19 -06:00
parent 9f93d0c1b7
commit 33c7884202
2 changed files with 10 additions and 0 deletions
+9
View File
@@ -322,6 +322,11 @@
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath {
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:NO];
}
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory {
BOOL success = NO;
NSFileManager *fileManager = nil;
@@ -338,6 +343,10 @@
NSString *fullFilePath = [directoryPath stringByAppendingPathComponent:fileName];
[fileManager fileExistsAtPath:fullFilePath isDirectory:&isDir];
if (!isDir) {
if (keepParentDirectory)
{
fileName = [[directoryPath lastPathComponent] stringByAppendingPathComponent:fileName];
}
[zipArchive writeFileAtPath:fullFilePath withFileName:fileName];
}
}