Created
June 7, 2024 22:19
-
-
Save lucadealfaro/751e1f4ca04f5b8f886a1476914fa280 to your computer and use it in GitHub Desktop.
zipit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
# 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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment