Bulk File Renamer
Operator: Abdulla Al Fahad. How tools are built and checked
Camera imports called IMG_4821, scans called Scan (3) copy, downloads with spaces and capital letters in all the wrong places: most folders need renaming at some point, and by hand it is slow. Dedicated renamers do it well, but they need installing and many of them hide what they are about to do.
This one shows everything first. Drop a folder, switch on the rules you want, and a table lists every current name beside its new name, with clashes and problems marked. Nothing is saved until the table looks right.
One limit shapes the output. A web page cannot rename files on your disk, so you get either a ZIP of renamed copies or a short script that renames the originals in place when you run it.
Key features
- Find and replace, plain or as a regular expression with $1 groups
- Eight case modes: unchanged, lower, upper, title, sentence, kebab, snake and camel
- Capture date from JPEG photos, or the modified date, in a format you choose
- Running numbers with padding, step, start, ordering and a restart per folder
- A live before-and-after table with clash, illegal-character and reserved-name checks
- A ZIP of renamed copies, shell and Windows scripts that rename in place, and a CSV mapping
Rename rules, conflicts and scripts
Any kind of file can be dropped, up to 5,000 at a time, with sub-folders included. Names, sizes and modified dates are read, and file contents are opened for one purpose only: when you ask for photo dates, the header of each JPEG is read to find the capture time the camera stored.
Rules run in a fixed order on the part of the name before the extension: trim, then find and replace, then letter case, then date, then running number, then prefix and suffix. The extension can be kept, lower-cased, upper-cased or set to a new one. Changing it renames the file but does not convert it.
Dates use the tokens YYYY, YY, MM, DD, HH, mm and ss, for example YYYY-MM-DD. A photo date comes from the JPEG's capture time, and a file without one, or one that is not a JPEG, falls back to its modified date and the table says so. Running numbers can start anywhere, step by any amount, be padded to 1 to 8 digits, follow the listed, name, date or size order, and restart in each folder.
A file that passes every check is labeled Will rename, one that keeps its name is labeled Same, and the rest are labeled Clash or Not allowed and held back. The ZIP holds every picked file, with the Will rename ones under their new names and the others under their old paths. The scripts cover only the Will rename files, while the CSV mapping lists every file with its status and notes.
How it works
Each file's name is split into stem and extension. The rules transform the stem in order, so a find and replace happens before the date is added and the number comes after the date. The result is then joined to the extension chosen by the extension rule.
Every new name is checked. The characters Windows does not allow (< > : " / \ | ? *) and control characters are replaced with an underscore and noted, and trailing dots and spaces are removed. Empty names, names over 255 characters and reserved Windows device names such as CON, NUL and COM1 are labeled Not allowed.
Two files that end up with the same name in the same folder, compared without regard to case, are a clash, labeled Clash. By default every file in the clashing group is flagged and held back, including a file whose name did not change. If you choose to make clashing names unique, the first keeps its name and the others become -2, -3 and so on.
The scripts rename in two passes. First every file that changes is moved to a temporary name, then each temporary name is moved to its final name, so a chain where a becomes b while b becomes c cannot overwrite anything. The Mac and Linux script uses mv with the no-clobber flag, and the Windows script uses ren.
Common use cases
- A 312-photo trip folder from two phones. Date taken, then numbering in date order, makes the file names sort in the order the pictures were shot even though the two cameras numbered theirs separately.
- Scan.pdf, Scan copy.pdf and Scan (1).pdf with a rule that strips " copy" and " (1)". All three would become Scan.pdf, so all three are held back as clashes; switching to unique names keeps Scan.pdf and makes the others Scan-2.pdf and Scan-3.pdf.
How to use this tool
- Drop a folder, or choose a folder or files.
- Switch on the rules you want and watch the preview table update.
- Fix anything labeled Clash or Not allowed, for example by adding a running number or a date.
- Choose how clashes are treated: held back, or made unique with -2, -3.
- Save the ZIP of renamed copies, or the script for your system, and run the script from the folder that contains the picked folder.
Example
Four files in Trip/, date prefix YYYY-MM-DD with _, running number by date taken, extension lower case
IMG_4821.JPG taken 2024-05-09 14:30
IMG_4822.JPG taken 2024-05-09 15:02
my photo (1).JPG taken 2024-05-10 09:00
clip.MOV no capture date, modified 2024-05-12New names
2024-05-09_IMG_4821_001.jpg
2024-05-09_IMG_4822_002.jpg
2024-05-10_my photo (1)_003.jpg
2024-05-12_clip_004.mov (note: no capture date found, used the modified date)Tips for best results
- Number by date rather than by the listed order when files come from several cameras. The listed order follows the order the browser hands the files over, which is not the order they were shot.
- Use a regular expression to reshape a name. Find ^(\d{4})(\d{2})(\d{2})_ and replace with $1-$2-$3_ and 20240509_IMG_4821.jpg becomes 2024-05-09_IMG_4821.jpg.
- To renumber a series in place, use numbering in replace mode. Three files 001.jpg to 003.jpg with a start of 2 become 002.jpg to 004.jpg, a chain the script handles safely.
Common pitfalls
A tab cannot rename files on your disk. The ZIP gives you renamed copies, and only running the script changes the originals.
Capture dates come from JPEGs only. PNG, HEIC and video files fall back to the modified date, which is often the date they were copied.
Changing an extension does not convert the file. Renaming photo.png to photo.jpg leaves PNG data inside it.
The Windows script switches the console to UTF-8, but a very old system may still show odd characters for non-English names. Check the CSV mapping if names look wrong.
Common errors and how to fix them
- Pattern problem: Invalid regular expression
- Escape special characters with a backslash, or untick the regular expression option to match the text literally.
- Same name as another file in this folder
- Two or more files would end up with one name. Add a running number or a date so the names differ, or choose to make clashing names unique with -2, -3.
- Reserved Windows device name
- A file would be named CON, PRN, AUX, NUL, COM1 to COM9 or LPT1 to LPT9, which Windows cannot create. Add a prefix or suffix.
Best practices
- Save the CSV mapping before you run a script. It records every old name next to its new one, and the scripts cannot be undone.
Why a swap or a chain needs two passes
Renaming 001.jpg to 002.jpg while 002.jpg is still there would overwrite it. The script avoids that by moving every changing file aside first. For three files numbered from 2, the Mac and Linux script is:
mv -n -- 'Scans/001.jpg' 'Scans/.rename-tmp-0' mv -n -- 'Scans/002.jpg' 'Scans/.rename-tmp-1' mv -n -- 'Scans/003.jpg' 'Scans/.rename-tmp-2' mv -n -- 'Scans/.rename-tmp-0' 'Scans/002.jpg' mv -n -- 'Scans/.rename-tmp-1' 'Scans/003.jpg' mv -n -- 'Scans/.rename-tmp-2' 'Scans/004.jpg'
What the name checks reject
A new name is changed or held back when it breaks one of these rules:
- The characters < > : " / \ | ? * and control characters become an underscore
- Trailing dots and spaces are removed, since Windows drops them silently
- A name that ends up empty, or longer than 255 characters, is invalid
- CON, PRN, AUX, NUL, COM1 to COM9 and LPT1 to LPT9 are invalid whatever the extension
Frequently asked questions
What happens to files whose name does not change?
They are left alone. The scripts only touch files labeled Will rename, and the ZIP keeps the other files under their old names.