Need help with a batch file

crazyman143

Fully Optimized
Messages
2,965
Maybe someone who's better at basic scripting than me can help me out.

Say I have a directory with files that have extension .srt.

I have a batch file that performs some functions, and I would like to add the ability to batch rename .srt files to .en.srt.

I have tried this, but the problem is if a file is already named correctly, it will become filename.en.en.srt:
REN *.srt *.en.srt

whats a better way to do this? thanks!
 
obviously the issue is that the file

test.en.srt is already captured by *.srt

there probably is a way of filtering *.that, but not *.this.that...
but personally I'd use a temporary pattern and three operations.

REN *.en.srt *.thisisatempextension
REN *.srt *.thisisatempextension
REN *.thisisatempextension *.en.srt


this way your file *.en.srt will be renamed to a non-matching state before you do your more general *.srt renaming... (so you avid the *.en.en.srt issue)

then with the last step you're just putting everything right.

or you could rename everything, and then deal with the duplicate .en's afterwards


REN *.srt *.en.srt
REN *.en.en.srt *.srt
 
You put me on the right track. But apparently there are some problems with double extensions in the rename command. Here's what I ended up with that works:
REN *en.srt *.
REN *.srt *.en
REN *.en *.en.srt

Drops the .srt off of any files named .en.srt
Renames any remaining .srt to .en
Renames all .en to .en.srt

Thanks for the help.
 
Back
Top Bottom