-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathzipit.py
24 lines (22 loc) · 1020 Bytes
/
zipit.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
import os
import zipfile
import shutil
def zip_all_in_folder(folder_path, base_path, output_zip):
# Create a ZIP file
with zipfile.ZipFile(output_zip, 'w', zipfile.ZIP_DEFLATED) as zipf:
# Walk through the directory
for root, dirs, files in os.walk(folder_path):
for file in files:
# Create the full path to the file
file_path = os.path.join(root, file)
if '/databases/' in file_path:
continue
# Write the file to the zip, adjust the arcname to customize how the paths are stored
zipf.write(file_path, arcname=os.path.relpath(file_path, start=base_path))
if os.path.exists('submission.zip'):
os.remove('submission.zip')
base_path = os.getcwd()
folder_path = os.path.join(base_path, 'apps')
# If apps is not in this folder, quit.
assert os.path.exists(folder_path), 'Folder "apps" not found in the current directory.'
zip_all_in_folder(folder_path, base_path, 'submission.zip')