-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip_creator.py
More file actions
29 lines (21 loc) · 915 Bytes
/
Copy pathzip_creator.py
File metadata and controls
29 lines (21 loc) · 915 Bytes
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
import zipfile
import pathlib
def make_archive(filepaths, dest_dir):
# output pathlib ==> dest/compressed.zip
dest_path = pathlib.Path(dest_dir, 'compressed.zip')
with zipfile.ZipFile(dest_path, 'w') as archive:
for filepath in filepaths:
filepath = pathlib.Path(filepath)
archive.write(filepath, arcname=filepath.name)
#test def function
if __name__ == "__main__":
make_archive(filepaths = ["question.py", "questions.json"], dest_dir = "dest")
# without def function
#filepaths = ["question.py", "questions.json"]
#output pathlib ==> dest/compressed.zip
#dest_path = pathlib.Path('dest', 'compressed.zip')
#create zip file ==> 'w', extract zip file ==> 'r'
#with zipfile.ZipFile(dest_path, 'w') as archive:
#for filepath in filepaths :
#filepath = pathlib.Path(filepath)
#archive.write(filepath, filepath.name)