Rename Photos in BATCH from text file prefix

Microsoft Windows 7 professional 64-bit
June 26, 2010 at 17:09:53
Specs: Windows 7
I am having difficulty figuring out the best way to rename my photos.

So far I have the following code:

@echo off
:Rename Photos
Echo Ex. photo959.jpg -- jpg 
set /p ext= Please enter the extension of your pictures: 
Echo Ex. photo959 -- photo    
set /p prefix= Please enter the prefix of the pictures that you would like renamed now: 
set /p desired= Please enter the desired prefix now: 
echo %desired% >prefix.txt

set /a grabpref=<prefix.txt
set /a desired=%grabpref%+1
ren "%CD%\%prefix%****" %desired%.%ext%
goto begin

I am having trouble with trying to grab the prefix from the text file and setting it as a variable.

I want this batch file to rename all my pictures that begin with "photo" to the specified prefix while adding consecutive numbers one after another.

The looping works fine if I replace

set /a grabpref=<prefix.txt
set /a desired=%grabpref%+1


set /a desired=%desired%+1

but then my prefix disappears and I'm left with nothing but consecutive numbers.

Help would be greatly appreciated. Thank you!

See More: Rename Photos in BATCH from text file prefix

Report •

June 26, 2010 at 21:59:13
you need to dispense with the squib-file ("prefix.txt") altogether, it's just making a hash of things.
you need 4 variables: extension, current prefix, new prefix,
and serial number (ie, counter).
After collecting the first three, (and not outputting to the squib-file), and making the egregious assumption that all the current files with given prefix are eligible targets:
... (do all the user-inputs etc.)
for /f "tokens=1* delims=[]" %%a in ('dir /b /o:n %prefix%*.%ext% ^|find /v /n ""') do echo ren "%%b" %desired%%%a.%ext%
::----- end
this is safetied for obvious reasons: (not tested!)
if the output looks okay, remove "echo" from the line.
normally, a counter-var would be used, but i wanted to try using "find /n" to provide it instead. (congrats, YOU"RE the guinea-pig, ha!)

Report •

June 27, 2010 at 11:40:07
Thank you so much for this reply. It works like a charm. I guess in the future I'll need to learn a few advanced commands, thank you so much.

Report •

Related Solutions

Ask Question