"""Zip EPS and JPG pairs For every EPS file that has a JPG with the same name, makes one ZIP holding both: "icon-set.eps" + "icon-set.jpg" become "icon-set.zip". Free script from LinearAndLoom Icons: https://linearandloomicons.netlify.app/scripts/ Provided as is. Renaming and zipping cannot be undone, so try it on a copy of your folder first. """ import os import zipfile from pathlib import Path def zip_eps_jpg_pairs(folder_path): """ For each pair of .eps and .jpg files with the same base name in `folder_path`, create a ZIP archive containing both files. The archive is named after the base name and placed in the same folder. """ folder = Path(folder_path).resolve() if not folder.is_dir(): print(f"Error: '{folder_path}' is not a valid directory.") return # Collect all .eps and .jpg files # Extensions are matched in any letter case (.eps, .EPS, .jpg, .JPG) eps_files = {f.stem: f for f in folder.iterdir() if f.is_file() and f.suffix.lower() == ".eps"} jpg_files = {f.stem: f for f in folder.iterdir() if f.is_file() and f.suffix.lower() == ".jpg"} # Find common base names (files that exist in both formats) common_stems = set(eps_files.keys()) & set(jpg_files.keys()) if not common_stems: print("No matching .eps / .jpg pairs found.") return for stem in sorted(common_stems): eps_path = eps_files[stem] jpg_path = jpg_files[stem] zip_path = folder / f"{stem}.zip" # Skip if ZIP already exists (optional: ask to overwrite) if zip_path.exists(): print(f"Warning: {zip_path.name} already exists. Skipping {stem}.") continue try: with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf: # Add both files, using their original names inside the archive zf.write(eps_path, arcname=eps_path.name) zf.write(jpg_path, arcname=jpg_path.name) print(f"Created: {zip_path.name}") except Exception as e: print(f"Failed to create ZIP for {stem}: {e}") if __name__ == "__main__": import sys # Get folder from command line argument, or ask interactively if len(sys.argv) > 1: target_folder = sys.argv[1] else: target_folder = input("Enter folder path containing .eps and .jpg files: ").strip().strip('"').strip("'") zip_eps_jpg_pairs(target_folder)