import os import zipfile # Path to your folder containing CSV files folder_path = r"C:\Users\David\Documents\DISK E\BI REPORTING\FLOYD REPORT\2025\CAPACITY\DECEMBRE\20151214" # Loop through all files in the folder for filename in os.listdir(folder_path): if filename.endswith(".csv"): csv_path = os.path.join(folder_path, filename) # Create a .zip file with the same name zip_filename = os.path.splitext(filename)[0] + ".zip" zip_path = os.path.join(folder_path, zip_filename) with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf: zipf.write(csv_path, arcname=filename) print(f"Zipped: {csv_path} → {zip_path}")