@@ -10,6 +10,27 @@ import Foundation
10
10
11
11
internal class ZipUtilities {
12
12
13
+ /*
14
+ Include root directory.
15
+ Default is true.
16
+
17
+ e.g. The Test directory contains two files A.txt and B.txt.
18
+
19
+ As true:
20
+ $ zip -r Test.zip Test/
21
+ $ unzip -l Test.zip
22
+ Test/
23
+ Test/A.txt
24
+ Test/B.txt
25
+
26
+ As false:
27
+ $ zip -r Test.zip Test/
28
+ $ unzip -l Test.zip
29
+ A.txt
30
+ B.txt
31
+ */
32
+ let includeRootDirectory = true
33
+
13
34
// File manager
14
35
let fileManager = FileManager . default
15
36
@@ -54,7 +75,7 @@ internal class ZipUtilities {
54
75
55
76
56
77
/**
57
- Recursive function to expand directory contents and parse them into ProcessedFilePath structs.
78
+ Expand directory contents and parse them into ProcessedFilePath structs.
58
79
59
80
- parameter directory: Path of folder as NSURL.
60
81
@@ -67,12 +88,15 @@ internal class ZipUtilities {
67
88
while let filePathComponent = enumerator. nextObject ( ) as? String {
68
89
let path = directory. appendingPathComponent ( filePathComponent)
69
90
let filePath = path. path
70
- let directoryName = directory. lastPathComponent
71
91
72
92
var isDirectory : ObjCBool = false
73
93
fileManager. fileExists ( atPath: filePath, isDirectory: & isDirectory)
74
94
if !isDirectory. boolValue {
75
- let fileName = ( directoryName as NSString ) . appendingPathComponent ( filePathComponent)
95
+ var fileName = filePathComponent
96
+ if includeRootDirectory {
97
+ let directoryName = directory. lastPathComponent
98
+ fileName = ( directoryName as NSString ) . appendingPathComponent ( filePathComponent)
99
+ }
76
100
let processedPath = ProcessedFilePath ( filePathURL: path, fileName: fileName)
77
101
processedFilePaths. append ( processedPath)
78
102
}
0 commit comments