forked from realpython/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18_zipper.py
More file actions
executable file
·40 lines (31 loc) · 1022 Bytes
/
18_zipper.py
File metadata and controls
executable file
·40 lines (31 loc) · 1022 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
30
31
32
33
34
35
36
37
38
39
40
import os
from datetime import datetime
from zipfile import ZipFile
# # set file name and time of creation
# today = datetime.now()
# file_name = 'zipper_' + today.strftime('%Y.%m.%dh%H%M') + '.zip'
# dir_name = 'tmp/' # update path
#
#
# def zipdir(path, zip):
# for root, dirs, files in os.walk(path):
# for file in files:
# zip.write(os.path.join(root, file))
#
# if __name__ == '__main__':
# zipfile = ZipFile(file_name, 'w')
# zipdir(dir_name, zipfile)
# zipfile.close()
today = datetime.now()
file_name = 'zipper_' + today.strftime('%Y.%m.%dh%H%M') + '.zip'
dir_name = 'tmp/' # update path
def add_folder_to_zip(folderPath,zipFile):
for root, dirs, files in os.walk(folderPath):
for file in files:
print(file)
print(root)
full_path = os.path.join(root,file)
zipFile.write(full_path)
with ZipFile("test_zip.zip","w") as my_zip:
print(my_zip)
add_folder_to_zip('testfolder',my_zip)