Zip Files by Type: One ZIP per Extension (Free Script)
Free Python script that sorts a folder into one ZIP per file type: svg.zip, png.zip, eps.zip. Handy for preparing digital download packs.
Download zip-files-by-extension.pyPython 3 · 59 lines · 2 KB · free
Digital products are usually delivered by format: one ZIP with the SVG files, one with the PNG files, one with the EPS files. This script builds those ZIPs from a mixed folder in one step.
What it does
- Groups the files in a folder by extension
- Makes one ZIP per type, named after the extension:
svg.zip,png.zip,eps.zip - Leaves the original files in place
- Treats
.PNGand.pngas the same type - Leaves existing ZIP files and subfolders alone
How to use it
- Run the script (see below). A folder window opens.
- Choose the folder that holds your files.
- The script lists each ZIP it creates and how many files went in.
- Type
Yand press Enter to do another folder, orNto finish.
How to run a Python script
- Install Python 3 from python.org if you do not have it. It is free. On Windows, tick Add Python to PATH in the installer.
- Download the script with the button on this page and save it somewhere easy, such as your Desktop.
- Open a terminal. On Windows, press the Windows key, type
cmdand press Enter. On Mac, open Terminal from Applications > Utilities. - Type
pythonfollowed by a space (on Mac,python3and a space), drag the script file into the terminal window and press Enter.
On Windows you can also just double-click the script after installing Python.
The folder window is drawn with Tkinter, which comes with Python on Windows and Mac. On Linux, install it with sudo apt install python3-tk.
What it is useful for
- Etsy and other digital downloads: shops limit how many files a listing can hold, so sellers upload one ZIP per format.
- Client handovers: send the print files and the web files separately.
- Archiving: shrink a folder of exports before backing it up.
Good to know
Running the script again on the same folder rebuilds each ZIP from the files that are there now, replacing the earlier svg.zip, png.zip and so on.
Questions
Can I change the ZIP names?
The ZIPs are named after the extension. Rename them afterwards, or use the find and replace script to add your product name.
Does it include files in subfolders?
No, only the files directly inside the chosen folder.
Is there a size limit?
No limit from the script. Check the upload limit of the shop or service you are sending the ZIP to.
The code
This is the complete script. Nothing else is downloaded or installed.
"""Zip files by extension
Sorts the files in a folder into one ZIP per file type:
all SVG files go into "svg.zip", all PNG files into "png.zip", and so on.
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 collections import defaultdict
from tkinter import Tk, filedialog
def zip_by_extension(folder):
groups = defaultdict(list)
for filename in os.listdir(folder):
filepath = os.path.join(folder, filename)
if os.path.isfile(filepath):
ext = os.path.splitext(filename)[1].lower().lstrip(".")
# ZIP files are left out, so archives from an earlier run are never zipped into themselves
if ext and ext != "zip":
groups[ext].append(filepath)
if not groups:
print("No files found.")
return
for ext, files in groups.items():
zip_path = os.path.join(folder, f"{ext}.zip")
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zf:
for file in files:
zf.write(file, arcname=os.path.basename(file))
print(f"Created: {ext}.zip ({len(files)} files)")
# Hide Tk window
root = Tk()
root.withdraw()
while True:
folder = filedialog.askdirectory(title="Select Folder to Process")
if not folder:
print("No folder selected.")
else:
print(f"\nProcessing: {folder}")
zip_by_extension(folder)
print("Finished.\n")
answer = input("Do you have another folder to process? (Y/N): ").strip().lower()
if answer not in ("y", "yes"):
break
print("Done.")
input("Press Enter to exit...")Download zip-files-by-extension.pyPython 3 · 59 lines · 2 KB · free
These scripts are free. If one saved you time, you can say thanks by buying a pack from the LinearAndLoom Etsy shop.


