python-scripts/18_zipper.py

21 lines
488 B
Python
Raw Normal View History

2014-08-17 00:23:00 +02:00
import os
from datetime import datetime
from zipfile import ZipFile
# set file name and time of creation
2014-08-17 00:23:00 +02:00
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()