|Awesome this works quite nicely. I can't recall using subroutines before this script so I never knew you could do things in the subroutine that don't work directly in for loops.|
The two lines under you comment about not understanding. The first line replaces everything before the numbers in the file name and the second line removes everything after the numbers. It's not exactly how I wanted to do it, but I can update that part now, using the same type of work around you came up with for the final replace.
Below is my final code (for now).
REM reads the episode titles into numbered variables, line 1 is episode 1 (!e1!), line 2 episode 2 (!e2!), etc, etc
set /a line=0
for /f %%a in (ep_titles.txt) do (
set /a line=!line!+1
REM loops through the files to have titles added to
for /f "delims=" %%I in ('dir /b *.test') do (
REM returns the episode number as !num!
REM removes zero padding from !num! as variables from before aren't zero padded
REM builds the episode title variable name
REM evaulates for the episode title
for /f %%A in ("!VAR2!") do set title=!%%A!
REM renames the filename if title isn't in it already
if not !end! == "" (
rename "%~dp0!fp!" "!beg!!num!_-_!title!!end:~3!"
REM if title is in file name already it clears !end! (basically the replace above does nothing)
if !end:~4! == !fp! set end=""
if !sigh! == 0 (
Well that's my updated script which appears to work find other than when certain characters are in the episode titles like ^!. I'm sure it's possible to escape those characters but I can't be bother to put more effort in this now. Considering I did make it in python and it's only around 10 lines and more robust.