I have, say, ten images that I'd like to rename in a looping fashion every night. I've written a batch file that does the following:
@echo off
cls
ren image10.jpg imagetemp.jpg
ren image1.jpg image10.jpg
ren image2.jpg image1.jpg
ren image3.jpg image2.jpg
ren image4.jpg image3.jpg
ren image5.jpg image4.jpg
ren image6.jpg image5.jpg
ren image7.jpg image6.jpg
ren image8.jpg image7.jpg
ren image9.jpg image8.jpg
ren imagetemp.jpg image9.jpg
exit
I'd like to rewrite this to be a loop since my image count just increased, however I'm having some issues - my script just terminates and the shell Window closes without letting me see any of the output (I had changed all "rens" to "echos" to see what the output would be). Here's my current attempt:
cls
ren image59.jpg imagetemp.jpg
ren image1.jpg image59.jpg
FOR %a IN (2 59) DO (
set t = %a% - 1
ren image%a%.jpg image%t%.jpg
)
ren imagetemp.jpg image58.jpg
exit
As I said before, I get either "a is unexpected", or when I try and change it to %%a, it just crashes and the window closes. Any tips?
pauseto see what the errors are? Also try using%%arather than%a%.set t=%a% - 1/A.