How to number files in the order you choose (not alphabetical or by date)
You want a story's pictures, a set of scans or a presentation's slides to come out as 001, 002, 003 in your order, but the renamer numbers them alphabetically or in some order you did not pick.
Why the numbers come out in the wrong order
A batch rename walks down a list and hands out 1, 2, 3 as it goes. Where that list comes from decides the result:
| Where the list comes from | Order you usually get |
|---|---|
| A file picker or drag and drop in a browser | Whatever the system hands over; often alphabetical, not always the order you clicked |
Plain ls or a *.jpg wildcard in a shell | Character-by-character, so IMG_10 before IMG_2 |
| File Explorer or Finder's own rename | Usually the order the window is sorted by, so check the sort column first |
| Sorting by date | The modified date, which is not always when a photo was taken (see below) |
So the dependable way is to look at the full before/after list, in order, before anything is renamed.
Step by step with the batch rename tool
- Choose or drop the files on the batch rename tool. Only the names (and, for chosen files, the modified date your computer reports) are read; nothing is uploaded.
- Get close with one click: A→Z (natural, so 2 comes before 10), Z→A, Reverse, or Oldest first / Newest first.
- Fine-tune by hand: drag a row, press its ▲ or ▼ button, or focus a row's button and press Alt + ↑ / ↓ (Alt + Home / End jumps to the top or bottom). The position number on each row is the number it will get.
- Set Numbering to Replace the name with a number and type a name in Add before, for example
Trip_, to getTrip_001.jpg,Trip_002.jpg. Or keep the names and put the number first (001_beach.jpg). - Check the preview, then copy the bash or PowerShell script and run it in that folder. It never overwrites a file, and the undo script puts the old names back.
Modified date is not "date taken"
Sorting photos oldest first sounds safe, but the date a computer shows for a file is its modified date. Copying, downloading from chat apps, editing or rotating a photo can all reset it to today, while the moment the photo was taken lives inside the file in its EXIF data (DateTimeOriginal). If a date sort looks wrong, that is usually why. Two fixes:
- Sort by eye: use Oldest first to get close, then drag the few stragglers into place.
- With ExifTool on your own computer, copy the taken date back onto the file's modified date:
exiftool "-FileModifyDate<DateTimeOriginal" *.jpg. Or name files by the taken date directly:exiftool "-FileName<DateTimeOriginal" -d "%Y-%m-%d_%H%M%S%%-c.%%e" ., which sorts correctly everywhere because the date is written biggest unit first.
Doing it in a shell
Write the names in the order you want into a text file, one per line, then number them in that order:
n=1
while IFS= read -r f; do
printf -v new 'Trip_%03d.%s' "$n" "${f##*.}"
mv -n -- "$f" "$new"
n=$((n+1))
done < order.txt
mv -n refuses to overwrite, so if a file is already called Trip_002.jpg it is skipped rather than lost; check afterwards for any names that did not change. In PowerShell, Get-Content order.txt piped into a loop with Rename-Item -LiteralPath and '{0:D3}' -f $n does the same.
Keep the order once it is set
- Pad the numbers (
001rather than1) so uploads, zips and scripts that sort character by character keep your order. More in why file10 sorts before file2. - Put the number first if other parts of the name differ, so
003_zebra.jpgstill follows002_apple.jpg. - Photos lying sideways? Turn them in the batch photo rotator, which can also number the fixed copies in the order you arrange them.
Related
Why file10 sorts before file2, and how to add leading zeros · How to batch rename files safely (without uploading them) · Why a batch rename overwrites or skips files (name collisions) · Batch rename tool (names only, in your browser) · Compress many photos at once · Invisible characters in text
Questions
How do I rename files in a specific order?
Put the list in that order first, then number it. In the batch rename tool, drag rows or use the arrow buttons until the position numbers match what you want, choose numbering, and check the preview before copying the script.
Why are my photos out of order when I sort by date?
The date most apps sort by is the file's modified date, which copying, downloading or editing can reset. The date the photo was taken is stored inside the file as EXIF DateTimeOriginal; ExifTool can copy it back onto the file date or put it in the name.
Does Windows rename (F2) number files in order?
When you select several files and rename them, Windows adds (1), (2) and so on, broadly following how the folder is sorted. Sort the window the way you want first and check the result; for exact control, use a preview list instead.
How many digits should the numbers have?
Enough for your largest number: 3 digits up to 999 files, 4 up to 9,999. Padded numbers keep the same order in every app.
Can I undo the new order?
In the batch rename tool, Undo order steps back through your moves and sorts before you copy anything. After running the script, the undo script puts the old names back.
Published .