1

I am working on a script that renames some files given to me by a client and automatically renames them to my naming convention.

Ex.: Files given by client:

Gallery-1-20160216.png
Gallery-2-20160216.png
Gallery-3-20160216.png
Gallery-4-20160216.png

My naming convention:

Gallery_1.png
Gallery_2.png
Gallery_3.png
Gallery_4.png

Here is the code I've written thus far:

REN Gallery-1* *Gallery_1.png
REN Gallery-2* *Gallery_2.png
REN Gallery-3* *Gallery_3.png
REN Gallery-4* *Gallery_4.png

While this works, I need to know if there is an easier way to write this, so that I can rename all 4 with one line. If there is a way to capture the numeric id of each "gallery" image.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • 3
    Here is a link to a person that marked this as resolved. http://stackoverflow.com/questions/17271586/rename-multiple-files-in-cmd – Cliff Stark Dec 13 '16 at 21:39
  • In a cmd window `For /f tokens=1-4 delims=-." %A in ('Dir /B /A-D Gallery-*-*.png') Do Rename "%A-%B-%C.%D" "%A_%B.%D"` but this really doesn't look easier ;-) –  Dec 13 '16 at 21:58
  • @LotPings, If the asterisk means '0 or more' then will `-*-*` this not be the same as `-*`? – Compo Dec 13 '16 at 22:10
  • There was a double quote missing, this should work `For /f "tokens=1-4 delims=-." %A in ('Dir /B /A-D Gallery-*-*.png') Do Rename "%A-%B-%C.%D" "%A_%B.%D"` –  Dec 13 '16 at 22:23
  • @Compo In a wildcard `*` means anything but the two hyphens have to be present. Do be more error proof it'l need findstr with a regex but this is nothing to enter regularly on the command line. –  Dec 13 '16 at 22:25
  • Why do you put a leading `*` to the new file name in your `ren` command lines? – aschipfl Dec 14 '16 at 00:19

0 Answers0