0
votes

My camera only numbers photos using 4 digits, but I am now well into the 5 digit realm. So for thousands of photos, I would like to add a fifth digit. E.g. rename IMG_2450 to IMG_12450.

I did this before about a year ago using Command Prompt, but I'm having trouble replicating those results today.

I tried: ren IMG_*.jpg IMG_1*.jpg

But what ends up happening is that instead of adding the number 1, command prompt ends up replacing the first character of the existing string of numbers.

So, IMG_2450 becomes IMG_1450 rather than IMG_12450.

What am I doing wrong here?

1

1 Answers

0
votes

This is untested - try it on some sample folders first.

It will process all the img_*.jpg files under the current directory tree and expects the filenames to be in the format you described.

@echo off
for /f "delims=" %%a in ('dir /ad /b /s') do (
pushd "%%a"
for /f "delims=" %%b in ('dir img_*.jpg /a-d /b') do (
for /f "tokens=1,* delims=_" %%c in ("%%b") do ren "%%b" "%%c_1%%d"
)
popd
)

If you want to process one folder only then try this (after testing):

@echo off
for /f "delims=" %%b in ('dir img_*.jpg /a-d /b') do (
for /f "tokens=1,* delims=_" %%c in ("%%b") do ren "%%b" "%%c_1%%d"
)