Go Back   Computer Forums > General Computing > Software and Operating Systems
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 08-21-2015, 08:41 PM   #1
Fully Optimized
 
crazyman143's Avatar
 
Join Date: May 2004
Location: USA
Posts: 2,946
Default Need help with a batch file

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:
Quote:
REN *.srt *.en.srt
whats a better way to do this? thanks!
__________________

crazyman143 is offline   Reply With Quote
Old 08-24-2015, 05:36 AM   #2
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,001
Default Re: Need help with a batch file

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
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 08-24-2015, 02:45 PM   #3
Fully Optimized
 
crazyman143's Avatar
 
Join Date: May 2004
Location: USA
Posts: 2,946
Default Re: Need help with a batch file

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:
Quote:
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.
crazyman143 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 12:45 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0