-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive.py
More file actions
37 lines (27 loc) · 1 KB
/
archive.py
File metadata and controls
37 lines (27 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import zipfile
import os
import platform
import shutil
def unpack(filePath):
"""Unpacks and deletes a zip file into the files current path"""
folderPath = os.path.dirname(filePath)
with zipfile.ZipFile(filePath) as f:
f.extractall(folderPath)
# Remove __MACOSX folder if present
macFolderPath = os.path.join(folderPath, "__MACOSX")
if os.path.exists(macFolderPath) and os.path.isdir(macFolderPath):
shutil.rmtree(macFolderPath)
os.remove(filePath)
def zipFolder(folderPath, destinationFilePath):
"""Zips a folder to a path"""
zipFile = zipfile.ZipFile(destinationFilePath, "w", zipfile.ZIP_DEFLATED)
originalDir = os.getcwd()
try:
os.chdir(folderPath)
for rootPath, dirs, files in os.walk("."):
for file in files:
if os.path.basename(file) != os.path.basename(destinationFilePath):
zipFile.write(os.path.join(rootPath, file))
zipFile.close()
finally:
os.chdir(originalDir)