-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_zip.py
36 lines (31 loc) · 1.19 KB
/
make_zip.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
import os
import zipfile
def zip_folder(src_folder: str, output_zip: str) -> None:
"""Zip a folder
Args:
src_folder (str): The folder to zip
output_zip (str): The output zip file
"""
# Remove the existing zip file if it exists
if os.path.exists(output_zip):
os.remove(output_zip)
# Create a zip file
added = []
with zipfile.ZipFile(output_zip, "w", zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(src_folder):
# Exclude certain directories and hidden files
dirs[:] = [d for d in dirs if not d.startswith(".") and d != "__pycache__" and d != "build"]
files = [f for f in files if not f.startswith(".")]
for file in files:
print(f"Adding... {file}")
zipf.write(
os.path.join(root, file), os.path.relpath(os.path.join(root, file), os.path.join(src_folder, ".."))
)
added.append(file)
if not added:
print("No files added to zip.")
else:
print(f"Added {len(added)} files to zip.")
if __name__ == "__main__":
# Usage
zip_folder("./src_static/", "./ai_shell/fish_tank.zip")