Add text to end of filename (but before extension) using batch file

Instead of relying on ren's undocumented quirks, why not do this the proper way?

for %a in (*.txt) do ren "%~a" "%~na version 1%~xa"

If you want to use this in a batch file just remember to double each % sign.


for longer filenames you will have to add some more ? in the block with the mass of ?????????

ren *.?* ????????????????????????????????????????????????????????" version 1".*

I wanted to add "_A" to multiple files and this is how I did it.

I removed the extension first, added the suffix, then changed extension back to original. It sure did work for me and kept the batch code simple, as I am not much of a programmer.

@ECHO OFF

REN *.pdf *.
REN *. *_A.
REN *. *.pdf