app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import os import zipfile def compress_folder_to_zip(folder_path, output_zip_path): with zipfile.ZipFile(output_zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf: for root, _, files in os.walk(folder_path): for file in files: file_path = os.path.join(root, file) # Preserve folder structure in the zip arcname = os.path.relpath(file_path, folder_path) zipf.write(file_path, arcname) print(f"All files in '{folder_path}' have been compressed into '{output_zip_path}'.") # Example usage: folder_to_compress = 'files' # Replace with your folder path output_zip_file = 'compressed_output.zip' # Output zip file name compress_folder_to_zip(folder_to_compress, output_zip_file) |