This is the kinda small script I use Claude for. So yeh, it's LLM generated. Downvote away.
But I am terrible at writing bash scripts!
#!/usr/bin/env bash
# rename-episodes.sh — run inside the folder, or pass a directory as $1
shopt -s nullglob
cd "${1:-.}" || exit 1
for f in *.mkv; do
# Match: ... Season N ... Episode N - Title.mkv
if [[ $f =~ Season\ ([0-9]+)\ Episode\ ([0-9]+)\ -\ (.+)\.mkv$ ]]; then
season="${BASH_REMATCH[1]}"
episode="${BASH_REMATCH[2]}"
title="${BASH_REMATCH[3]}"
# Zero-pad to two digits
new=$(printf "S%02dE%02d - %s.mkv" "$season" "$episode" "$title")
if [[ "$f" != "$new" ]]; then
echo "mv: $f -> $new"
# uncomment the next line to actually move the file
# mv -n -- "$f" "$new"
fi
else
echo "skip (no match): $f"
fi
done
I've commented out the mv command so you can test/fiddle/play around with it without clobbering your files.
Some notes from Claude:
Two practical notes:
If your files aren't all .mkv, change the glob (*.mkv) and the regex anchor accordingly, or loop over *.{mkv,mp4,avi}.
This assumes the literal words "Season" and "Episode" appear. If your real filenames vary (e.g. "S1", "1x01", "Ep 1"), the regex needs adjusting
Edit: I just realised that specifically file-rename is mentioned, and looks like you are getting appropriate help in other threads.