-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path7v2.py
More file actions
21 lines (19 loc) · 730 Bytes
/
7v2.py
File metadata and controls
21 lines (19 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
import zipfile
def backup_to_zip(folder):
folder = os.path.abspath(folder)
number = 1
while True:
zip_filename = os.path.basename(folder) + '_' + str(number) + '.zip'
if not os.path.exists(zip_filename):
break
number += 1
print(f'Creating {zip_filename}...')
with zipfile.ZipFile(zip_filename, 'w') as zip_file:
for foldername, subfolders, filenames in os.walk(folder):
print(f'Adding files in {foldername}...')
for filename in filenames:
file_path = os.path.join(foldername, filename)
zip_file.write(file_path, arcname=os.path.relpath(file_path, folder))
print('Done.')
backup_to_zip('python')