-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzipper.py
More file actions
23 lines (18 loc) · 834 Bytes
/
zipper.py
File metadata and controls
23 lines (18 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import zipfile
import os
def zip_directory(directory, zip_file):
"""
Compresses the specified directory into a zip file.
:param directory: Path to the directory to be compressed.
:param zip_file: Path to the output zip file.
"""
with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, _, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
zipf.write(file_path, os.path.relpath(file_path, directory))
if __name__ == "__main__":
directory_to_zip = r'<abolute path to file goes here>'
output_zip_file = r'<absolute path including file name goes here'
zip_directory(directory_to_zip, output_zip_file)
print(f"Directory '{directory_to_zip}' zipped successfully to '{output_zip_file}'.")