Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 and variations like: 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?

share|improve this question

Here's what you need. Run the following command:

for /f "tokens=1,2 delims=_" %a in ('dir /b img_*.jpg') do @echo ren "%a_%b" "%a_1%b"

If you're happy with the output, delete the @echo and run it again.

share|improve this answer

Try this:

FOR %v IN (IMG_*.jpg) DO REN %v 1%v


share|improve this answer
Pretty sure last time I saw lfnfor was back in Win9x, and I doubt the OP's still using that. – Karan May 20 '13 at 21:49
@Karan sorry, copied verbatim... – Kruug May 20 '13 at 21:55
Command's still incorrect BTW; try it and see where the 1 ends up. – Karan May 20 '13 at 22:04
Well, that might work if Michael is using Windows 95, 98, or Me, but Wikipedia says that those are the only versions of Windows that support the LFNFOR command. You might want to think twice before quoting from a page that refers to the Windows Command Prompt as “Dos” and refers to quotes as “inverted commas”. – Scott May 20 '13 at 22:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .