-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZip_file_maker.py
50 lines (42 loc) · 1.59 KB
/
Zip_file_maker.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Project: Create Zip File Maker
Author: S.Brahma
Date: 28/1/2017
Problem: The user enters various files from different directories and the program zips them up into a zip file.
Optional: Apply actual compression to the files. Start with Huffman Algorithm. import os, datetime
"""
import os, datetime
source_dir = '/Users/Sam/python' # please change it accordingly
upload_time = datetime.datetime.now().strftime("%Y-%m-%d")
target_dir = '/Users/Sam/python/backup'
if not os.path.exists(target_dir):
os.makedirs(target_dir)
folder = os.path.join(target_dir, upload_time ) # please change it accordingly
filename = folder + '.zip'
zip_command = "zip -qr '%s' %s" %(folder,source_dir)
# run zip command
if os.system(zip_command) == 0:
print " the file %s is successfully zipped" %filename
else:
print "Backup failed."
# Another version discussed in the book "A byte of Python"
# import os
# import time
# # 1. The files and directories to be backed up are specified in a list.
# source = ['/Users/Sam/python']
#
# # 2.The backup must be stored in a main backup directory
# target_dir ='/Users/Sam/python/backup'# Remember to change this to what you will be using
#
# # 3. The files are backed up into a zip file.
# # 4. The name of the zip archive is the current date and time
# target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
#
# # 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
# zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
#
# # Run the backup
# if os.system(zip_command) == 0:
# print 'Successful backup to', target
# else:
# print 'Backup FAILED'