Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
Zip
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
YongYue
Zip
Commits
f0d114fd
Commit
f0d114fd
authored
Nov 26, 2017
by
Roy Marmelstein
Committed by
GitHub
Nov 26, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #114 from peterboni/patch-2
Added includeRootDirectory logic.
parents
c8cee3e1
8e282b60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
3 deletions
+27
-3
Zip/ZipUtilities.swift
Zip/ZipUtilities.swift
+27
-3
No files found.
Zip/ZipUtilities.swift
View file @
f0d114fd
...
...
@@ -10,6 +10,27 @@ import Foundation
internal
class
ZipUtilities
{
/*
Include root directory.
Default is true.
e.g. The Test directory contains two files A.txt and B.txt.
As true:
$ zip -r Test.zip Test/
$ unzip -l Test.zip
Test/
Test/A.txt
Test/B.txt
As false:
$ zip -r Test.zip Test/
$ unzip -l Test.zip
A.txt
B.txt
*/
let
includeRootDirectory
=
true
// File manager
let
fileManager
=
FileManager
.
default
...
...
@@ -54,7 +75,7 @@ internal class ZipUtilities {
/**
Recursive function to e
xpand directory contents and parse them into ProcessedFilePath structs.
E
xpand directory contents and parse them into ProcessedFilePath structs.
- parameter directory: Path of folder as NSURL.
...
...
@@ -67,12 +88,15 @@ internal class ZipUtilities {
while
let
filePathComponent
=
enumerator
.
nextObject
()
as?
String
{
let
path
=
directory
.
appendingPathComponent
(
filePathComponent
)
let
filePath
=
path
.
path
let
directoryName
=
directory
.
lastPathComponent
var
isDirectory
:
ObjCBool
=
false
fileManager
.
fileExists
(
atPath
:
filePath
,
isDirectory
:
&
isDirectory
)
if
!
isDirectory
.
boolValue
{
let
fileName
=
(
directoryName
as
NSString
)
.
appendingPathComponent
(
filePathComponent
)
var
fileName
=
filePathComponent
if
includeRootDirectory
{
let
directoryName
=
directory
.
lastPathComponent
fileName
=
(
directoryName
as
NSString
)
.
appendingPathComponent
(
filePathComponent
)
}
let
processedPath
=
ProcessedFilePath
(
filePathURL
:
path
,
fileName
:
fileName
)
processedFilePaths
.
append
(
processedPath
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment