forked from nitin42/Python-Automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project8.py
35 lines (20 loc) · 785 Bytes
/
project8.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
# Backup of folder into a zip file
# Copies the whole contents of any folder into a zip file whose filename increaments
# File format should be like this filename_number.zip (number should be increamented)
def backup(folder):
# Backup the content of folder into a zip file
folder = os.path.abspath(folder)
number = 1
while True:
zip_name = os.path.basename(folder) + '_' + str(number) + '.zip'
if not os.path.exists(zip_name):
break
number = number + 1
print ("Creating file %s" %(zip_name))
backupzip = zipfile.ZipFile(zip_name,'w')
# Walking through the whole directory
for foldername, subfolders, filenames in os.walk(folder):
print ('Adding the file %s'%(foldername))
backupzip.write(foldername)
backupzip.close()
print ('Succeeded')