-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzipper.py
36 lines (28 loc) · 894 Bytes
/
zipper.py
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
import os, zipfile
# get the current path and lis of the files and folders
currecnt_directory = os.curdir
myfile_list = os.listdir(currecnt_directory)
# make a progressbar:
prgress_bar = len(myfile_list)
print(prgress_bar, "items\r\n ")
# create a new zip file
newzipfile = zipfile.ZipFile("newzipfie.zip", "w")
# add files and folders into the zipfile
def time_decorator(func):
def wrapper(*args, **kwargs):
import time
t1 = time.clock()
func(*args)
t2 = time.clock()
print("{name} : {time:10.10f}".format(name=func.__name__, time=t2 - t1))
return wrapper
@time_decorator
def ziping_func(myfiles, newzip, directory):
i = 1
for item in myfile_list:
newzip.write(directory + "\\" + item)
print(i, )
i += 1
# close the zip file
newzip.close()
ziping_func(myfile_list, newzipfile, currecnt_directory)