Websites, apps & code / Coding & debugging
Python for a batch of files
You have hundreds of files to process and doing it by hand is too slow.
1Fill in your details
Leave blank to use the example. Names are remembered for other prompts too (stored only on your device).
3Copy the prompt
Please write a small Python script to process a batch of files. Task: Rename 300 photos by date and sort into month folders. Where the files are: The "Desktop/event photos" folder on my computer Requirements: - first ask me 3 questions - the script starts with a backup or a dry run that only prints what it would do; it acts only after I confirm - add a one-line comment per section - never delete files - teach me how to run it step by step, assuming I am new - fit my computer - Use Mac Terminal steps. - Use only the details I give you. Do not invent anything. If something is missing, leave it as [ ] or ask me. Output format: Questions, then the script and how to run it. [Make it sound human] - Explain in plain words; no pleasantry openers or empty summaries. - Only necessary, short, practical code comments; the simplest working approach, no over-engineering. - Interface text (buttons, hints, error messages) should sound like a person wrote it; no "seamless", "empower", "unlock". [Quality] Code must run as is and handle common errors; tell me how to test it and confirm it works; ask first if a requirement is unclear; never put passwords or API keys in the code.
Paste it into ChatGPT, Gemini, Claude or Meta AI.
Test result
What we noticed
It asked 3 questions and also gave a dry-run script. I did not execute it, and Pillow versions may differ on _getexif; unreadable shot dates fall back to the modified date, which users should know.
See what the AI actually wrote
Three questions first:
- Were the photos taken on a phone? Phone photos carry the shot date (EXIF). Without it I can only use the modified date, which is less accurate.
- What should the new names look like? For example 2025-04-03_001.jpg, with month folders like 2025-04?
- Copy to month folders, or move? (I suggest copy, so the originals are untouched and safest.)
My assumptions for now: phone photos, names like 2025-04-03_001.jpg, folders like 2025-04, copy and keep originals.
Backup and dry run:
- First copy the whole Desktop/活动照片 folder and name it "活动照片备份".
- The program starts with a dry run: it only prints "old name to new location/new name" and touches nothing. You read it, and type y to really copy.
- Nothing is deleted.
Mac Terminal, step by step:
- Press Command + Space, type "Terminal", press Enter.
- Check Python: type python3 --version and press Enter. A version number means it is there; if not, download from python.org.
- Install the photo-date reader: type pip3 install pillow and press Enter.
- Save the code below as organize.py on the desktop (TextEdit, plain text format).
- Type cd ~/Desktop, press Enter, then python3 organize.py, press Enter.
Code (one line of comment per part):
import os, shutil
from datetime import datetime
from PIL import Image
SRC = os.path.expanduser("~/Desktop/活动照片") # folder with the photos
DST = os.path.join(SRC, "organised") # copies go here, originals untouched
def taken_date(path): # read the shot date, fall back to modified date
try:
exif = Image.open(path)._getexif() or {}
raw = exif.get(36867) # time taken
if raw:
return datetime.strptime(raw, "%Y:%m:%d %H:%M:%S")
except Exception:
pass
return datetime.fromtimestamp(os.path.getmtime(path))
plan, count = [], {}
for f in sorted(os.listdir(SRC)): # jpg only
if not f.lower().endswith((".jpg", ".jpeg")):
continue
p = os.path.join(SRC, f)
d = taken_date(p)
key = d.strftime("%Y-%m-%d")
count[key] = count.get(key, 0) + 1
new = f"{key}_{count[key]:03d}.jpg"
plan.append((p, os.path.join(DST, d.strftime("%Y-%m"), new)))
for a, b in plan: # dry run: print only
print(a, "->", b)
if input("%d photos. Really copy? (y/n) " % len(plan)).lower() == "y":
for a, b in plan:
os.makedirs(os.path.dirname(b), exist_ok=True)
shutil.copy2(a, b)
print("Done")
Test: make a "test" folder with 3 photos, change the SRC line to "test", run once, check the table and, after typing y, that "organised" holds month folders. Then go back to the 300.
Answer my 3 questions and I will adjust the names and folders.
AI tools that suit this
- ChatGPT Suggested tool Free plan
The most widely used AI chat, for writing, questions and images
- Claude Suggested tool Free plan
Strong at long documents, editing and code
- Claude Code Suggested tool Free plan
AI that writes code directly on your computer
Recommendations only, not sponsored. Check each site for what the free plan includes.
This site is made by FullMark Tech
Want your own website, or your shop spreadsheets automated? FullMark Tech builds business websites and custom Excel tools.