How to rename hundreds of files at once
Bulk renaming goes wrong in one specific way, and it is worth knowing what it is before you run anything.
Short answer
Check the whole batch for collisions before renaming a single file. If two files would end up with the same name, one of them is about to be overwritten — and every other failure mode is recoverable by comparison.
The one thing that actually goes wrong
Most bulk-rename mistakes are annoying and reversible. You get the wrong number of digits, or the date format reads backwards, or you strip a prefix you wanted. Everything is still there, and you can rename again.
There is one exception. If your rule maps two different files onto the same new name, the second one overwrites the first, and that file is gone. It happens more easily than you would think:
- Removing a distinguishing part of the name.
2024-01-05 report.pdfand2024-02-05 report.pdfboth becomereport.pdfif you strip dates. - Renumbering a folder where the sort order is not what you assumed.
- Renaming case-insensitively on Windows or macOS, where
Photo.jpgandphoto.jpgare the same name. - Flattening subfolders into one directory, where names were only ever unique within their folder.
So the rule is: validate the whole batch first, and refuse to start if any two files would collide. Not fail partway — refuse to start. A rename job that stops halfway leaves a folder in a state that is much harder to reason about than one that never began.
Preview, then apply
Anything that renames files should print the complete list of old → new and stop, unless you explicitly say go. Read a dozen lines of it. That is where you catch the date format being wrong, or the regular expression matching one character more than you meant.
The same applies to renumbering. Look at what it plans to call the first file and the last file, and check the padding: photo-1.jpg through photo-100.jpg sorts as 1, 10, 100, 11 in every file browser there is. photo-001.jpg does not.
Have an undo
A journal of what was renamed to what, written as it goes, turns a bad rename from a problem into an inconvenience. Reverse it newest-first and you are back where you started.
This matters more than it sounds, because the mistakes you make are the ones you did not anticipate, and “I will just rename them back” stops being possible the moment the new names have lost information the old ones carried.
What the operating system already gives you
For simple cases you may not need anything.
Windows Explorer: select several files, press F2, type a name. You get name (1).jpg, name (2).jpg. Crude, no padding, but instant. PowerShell does more:
Get-ChildItem *.jpg | Rename-Item -NewName { $_.Name -replace 'IMG_','holiday-' } -WhatIf
-WhatIf is the preview. Remove it to run.
macOS Finder: select several files, right-click, Rename. It does find-and-replace, add-text, and format-with-a-counter, including zero padding, and it is genuinely good. For a folder of holiday photos this is the whole answer.
Anywhere with a shell, a preview loop:
for f in *.JPG; do echo mv "$f" "${f%.JPG}.jpg"; done
Drop the echo when the output looks right.
Reach for something else when you need a real pattern language, when the batch is large enough that you cannot eyeball it, when the operation is conditional on what the file is rather than what it is called, or when you want an undo.
The programs for this
- FilePilot does the two common jobs:
renameis regex find-and-replace across basenames,sequencerenumbers a batch with a pattern likephoto-{n}.jpg, with--start,--padand a choice of sort order. Both print the planned renames and change nothing unless you pass--apply. - FileOps adds a template language and the two safety features above: it validates the whole batch for collisions before it starts, and it writes a journal that
undoreverses newest-first.previewis read-only and never touches the filesystem at all. - FolderForge sorts rather than renames: rules in a file, first match wins, the whole batch validated for collisions before anything moves, and files matching no rule left exactly where they are.
- FileDeck takes the plan as a spreadsheet — one row per file, saying what should happen to it.
validatechecks the entire plan and reports every problem at once with the row number of each, so you fix a CSV rather than discovering issues one at a time.
Free while we are in preview, one file each, Windows and Mac.