My camera records images as IMG_0001.JPG through IMG_9999.JPG, at which point the next image taken rolls over and becomes IMG_0001.JPG again. This gives me problems for various reasons and I’d really like if instead it became IMG_10001.jpg.
The camera isn’t going to do it, but I can just go ahead and rename the files on my computer.
But the command prompt rename command won’t work - long story short, it’s very stupid, won’t generate names except in 8.3 format, and doesn’t work right anyway - the command “ren img_???.jpg AA???.jpg”, which should turn img_0001.jpg into AA0001.JPG instead turns it into AAg_0001.jpg. It retains the “g_” characters for no reason. So that’s garbage.
Anyway, how can I go about automatically renaming these files to add a 1 in front of them?
If you download the Zip Archive you don’t even need to do a regular install. Just unzip it to a folder, and open the exe file. It works fine on my Win7 box, and has a pretty powerful little set of tools for renaming.
Rename utilities are definitely the way to go, beacuse the command line rename operation is notoriously finicky. If you really want to do it with the command line, you need to use a FOR loop. Take a look at wcrename.bat (Google it), for example.
If you really want to use batch files, you just need to adjust your goal to meet it’s limitations. You can rename files in the form img_???.jpg to anything else, as long as you keep your prefix the same length as the one you’re replacing. In this case that’s 4 characters.
for example, img_???.jpg ->0000???.jpg. That covers your first 10,000 files.
then use img_???.jpg ->0001???.jpg . Now you’ve got your next 10,000.
I often find that when a tool won’t *quite *do what I want that it’s because I’ve chosen too rigid a definition of what I want.
FYI, if you like messing with batch files you can do exactly what you want with artful use of the for & set commands in a batch subroutine. There are certainly better & easier to use tools for the job, but if you like playing stupid dev tricks from the 90s, you can get the job done just using built-in CMD capabilities
This was actually the first thing I tried (“ren img_.jpg img_1.jpg”), but adding the character exceeds the 8.3 limit, which results in the first wildcard character being changed to a 1 rather than having 1 added. img_0001.jpg became img_1001.jpg rather than img_10001.jpg.
It doesn’t need to come from a batch file, I just meant batch processing as in automatically doing a whole bunch of them at once. I’ll check out those rename utilities, thanks.
No, you didn’t try what I suggested. You tried adding a character.
I’m suggesting substituting 4 characters (“0000” or “0001”) for the 4 characters “img_”.
ren img_????.jpg 0000????.jpg
That *will *work.
Whether it does what you really want is a separate issue. And yes, I agree that this problem is better solved by one of the dedicated rename utilities.
You don’t need a batch file. Select them all in Windows Explorer, right-click, Rename, and type the first filename. Windows will then sequence them for you.
Try Total Commander. formerly known as Windows Commander, inspired by Norton Commander from the old days. It’s a shareware program that I’ve used forever. (Gnome Commander is its FOSS counterpart.) Nothing you couldn’t do from the command line but sometimes I just prefer a clean, functional GUI. Either program will let you select a bunch of files, hit control-m and then select from a bunch of commands how you want the files renamed. You can search & replace, append characters, add a series, etc. Or completely rename them as Beef001.doc, Beef002.doc, etc.
The result is in column F. Copy rows down as needed, ensuring that column A increments and column E does not. Copy column F into notepad and save as a .BAT
The software for downloading the pictures from my Nikon camera has many options to change the file names as the pictures are being downloaded. Your software might have similar options which you could use in the future.
For me, there’s nothing like Bulk Rename Utility. It’s freeware and fairly intuitive.
Sure, it looks a bit daunting, with all the options, but that’s only until you realize that they are mostly different ways of doing the same thing. Just select the files you want renamed and a preview of the result will appear.
Paste the script below into a text file with a .cmd extension (don’t give it the same name as a native command like rename). Change the value of the folder variable to the location of the folder containing the files.
Running the script will echo the commands to be executed. Once you have tested it and are certain it will do what you want, remove the bolded ECHO command to rename the files.
@echo off
setlocal enabledelayedexpansion
set **folder**=c:\photos
set mask=IMG_????.JPG
for /f "tokens=*" %%G in ('dir "%folder%\%mask%" /a:-d /b') do (
set oldname=%%~nxG
set newname=!oldname:~0,4!1!oldname:~-8!
if not exist "%folder%\!newname!" (
**ECHO** ren "%folder%\%%G" "!newname!"
)
)
pause