Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a list of files which are in the format on the left. I want to append a string to each file name, but before the extension, as shown:

File 1.txt  ->  File 1 version 1.txt
File 2.txt  ->  File 2 version 1.txt
File 3.txt  ->  File 3 version 1.txt
File 4.txt  ->  File 4 version 1.txt
...

In each case, the appended string is the same across all files.

This seems like such a simple task, but I'm having some trouble putting this into a batch file.

I've tried the ren command and followed some the the examples on this page, but the resulting file names append the string after the extension:

File 1.txt version 1.txt
share|improve this question
    
The info at your SS64 "this page" link comes from this SU Q&A (with my blessing): How does the Windows RENAME command interpret wildcards? I maintain the SU answer (infrequently) as I discover new features. –  dbenham Jun 5 '13 at 13:58
add comment

2 Answers

up vote 4 down vote accepted

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

ren *.?* ????????????????????????????????????????????????????????" version 1".*
share|improve this answer
1  
Thanks for answering so promptly! I edited the command slightly, to retain the file extension, and to only affect txt files: ren *.txt ?????????????????????????" Version 1.txt" –  TheTurkey Jun 5 '13 at 11:13
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.