Discussion:
Making Filenames Mirror One Another With Different Extensions
(too old to reply)
AlleyCat
2016-01-17 22:20:39 UTC
Permalink
Hello all. I think this will be simple for you batch and script gurus, but
it's driving me crazy.

Videofile: House.S08E18.Body And Soul.mkv

Subtitle: House.S08E18.HDTV.XviD-LOL.srt

If you please... copy text after third period (or whatever will be before
the extension in other cases) of videofile and copy it to the srt file, so
both files are identical other than the extension.

Sample: House.S08E18.Body And Soul.mkv
House.S08E18.Body And Soul.srt

Not all vid files are in this "format", but I'll work on it from there.

Thank you so very much.
foxidrive
2016-01-18 14:41:08 UTC
Permalink
This was crossposted to various places.
Post by AlleyCat
Videofile: House.S08E18.Body And Soul.mkv
Subtitle: House.S08E18.HDTV.XviD-LOL.srt
so both files are identical other than the extension.
Sample: House.S08E18.Body And Soul.mkv
House.S08E18.Body And Soul.srt
This can be done by using the initial term "House.S08E18" and isn't so hard.
Run this script in an empty folder - it creates the sample files to test it
with.

The ren command is only printed to the console at present - you can remove
the 'echo' to make it perform the rename.


@echo off
break>"House.S08E18.Body And Soul.mkv"
break>"House.S08E18.HDTV.XviD-LOL.srt"

for %%a in ("house*.mkv") do (
for /f "tokens=1,2 delims=." %%b in ("%%~a") do (
for %%d in ("%%b.%%c*.srt") do echo ren "%%~d" "%%~na%%~xd"
))
pause


The difficulty is in the various format of the files.
AlleyCat
2016-01-18 22:19:56 UTC
Permalink
On Tue, 19 Jan 2016 01:41:08 +1100, foxidrive says...
Post by foxidrive
@echo off
break>"House.S08E18.Body And Soul.mkv"
break>"House.S08E18.HDTV.XviD-LOL.srt"
for %%a in ("house*.mkv") do (
for /f "tokens=1,2 delims=." %%b in ("%%~a") do (
for %%d in ("%%b.%%c*.srt") do echo ren "%%~d" "%%~na%%~xd"
))
pause
The difficulty is in the various format of the files.
Thank you SO much!

for %%a in ("house*.mkv") do (
for /f "tokens=1,2 delims=." %%b in ("%%~a") do (
for %%d in ("%%b.%%c*.srt") do ren "%%~d" "%%~na%%~xd"))

Pared it down to this and it works great. Thank you, very much!
AlleyCat
2016-01-19 01:30:55 UTC
Permalink
Not all files, either the video OR the subtitle files, come in that
particular format. Some might look like this:

House.S08E18.Body And Soul.mkv

House.MD.S08E18.HDTV.XviD-LOL.srt

What I'd really like, is to match files that have the same season and
episode, and change the srt (subtitle) file to match the video file.

Even if the srt ONLY has the season and episode disignation, I'd like it
to match with the video file and rename.

I realize it HAS to be hard to get a batch file to look at the whole
directory, compare files and pick out the ones with matching "SxxExx"'s
and rename the srt file only.

Video file: House.S08E18.Body And Soul.mkv

Subtitle file: S08E03.srt

to House.S08E18.Body And Soul.srt

Just need them to match for subtitle to work.

I've already finished the project I'm on now, so please... do NOT take
time out to do this unless you WANT to.

If you could make that work, you could probably SELL that script or batch
to pirates like me! LOL

Thanks again.
Todd Vargo
2016-01-19 04:26:49 UTC
Permalink
Post by AlleyCat
Not all files, either the video OR the subtitle files, come in that
House.S08E18.Body And Soul.mkv
House.MD.S08E18.HDTV.XviD-LOL.srt
What I'd really like, is to match files that have the same season and
episode, and change the srt (subtitle) file to match the video file.
Even if the srt ONLY has the season and episode disignation, I'd like it
to match with the video file and rename.
I realize it HAS to be hard to get a batch file to look at the whole
directory, compare files and pick out the ones with matching "SxxExx"'s
and rename the srt file only.
Video file: House.S08E18.Body And Soul.mkv
Subtitle file: S08E03.srt
to House.S08E18.Body And Soul.srt
Just need them to match for subtitle to work.
I've already finished the project I'm on now, so please... do NOT take
time out to do this unless you WANT to.
If you could make that work, you could probably SELL that script or batch
to pirates like me! LOL
Thanks again.
S08E18 does not match S08E03. Originally, you posted matching examples.
Now they don't match. Did you make a typo in this Subtitle example?
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
AlleyCat
2016-01-19 05:30:16 UTC
Permalink
On Mon, 18 Jan 2016 23:26:49 -0500, Todd Vargo says...
Post by Todd Vargo
S08E18 does not match S08E03. Originally, you posted matching examples.
Now they don't match. Did you make a typo in this Subtitle example?
LOL... yes. I was copying pasting and wanted to use a different example
than S08E18, and forgot to use the srt version of S08E03.

Sorry.

Todd, do you think it's possible for a batch file/script to search a
folder and see like files and rename the srt to match the mkv?

Hell, I'd settle for a mini program compiled to do it. I've got a friend
who writes code, but he's too busy with his life. LOL
foxidrive
2016-01-19 10:41:44 UTC
Permalink
Post by AlleyCat
Todd, do you think it's possible for a batch file/script to search a
folder and see like files and rename the srt to match the mkv?
Is this project still underway then?

Would this be run in a folder with videos of only one single show?
AlleyCat
2016-01-20 07:54:23 UTC
Permalink
On Tue, 19 Jan 2016 21:41:44 +1100, foxidrive says...
Post by foxidrive
Post by AlleyCat
Todd, do you think it's possible for a batch file/script to search a
folder and see like files and rename the srt to match the mkv?
Is this project still underway then?
Not at the moment... the script you sent worked perfectly, for THESE
files. Like I said though, at some time I'm going to have files that
aren't so "alike", meaning they will most likely have ONLY the SxxExx in
common, and that is hopeful, but that's USUALLY the standard.

This could be the video file: House.S08E11.Nobody's Fault.xxx
And this could be the subtitle file: S08E11.House.srt

I would need for the script to find "x", x being the SxxExx, and rename
the srt file to match the vid file.
Post by foxidrive
Would this be run in a folder with videos of only one single show?
Show yes... ONE show (episode)? LOL... oh hell no... if it was only one
show (episode) and subtitle, I'd rename it myself. This could involve, in
this case anyways, 8 seasons of 20-24 episodes with corresponding subtitle
files, that aren't always named the same way.

I would never mix different shows in the same folder, so there won't ever
be duplicate SxxExx's in the same folder.


Example: Season 8 of House MD

House.S08E01.HDTV.XviD-LOL.srt
House.S08E01.Twenty Vicodin.mkv

House.S08E02.HDTV.XviD-LOL.srt
House.S08E02.Transplant.mkv

House.S08E03.Charity Case.mkv
House.S08E03.HDTV.XviD-LOL.srt

House.S08E04.HDTV.XviD-LOL.srt
House.S08E04.Risky Business.mkv

House.S08E05.HDTV.XviD-LOL.srt
House.S08E05.The Confession.mkv

House.S08E06.HDTV.XviD-LOL.srt
House.S08E06.Parents.mkv

House.S08E07.Dead and Buried.mkv
House.S08E07.HDTV.XviD-LOL.srt

House.S08E08.HDTV.XviD-LOL.srt
House.S08E08.Perils of Paranoia.mkv

House.S08E09.Better Half.mkv
House.S08E09.HDTV.XviD-LOL.srt

House.S08E10.HDTV.XviD-LOL.srt
House.S08E10.Runaways.mkv

House.S08E11.HDTV.XviD-LOL.srt
House.S08E11.Nobody's Fault.mkv

House.S08E12.Chase.mkv
House.S08E12.HDTV.XviD-LOL.srt

House.S08E13.HDTV.XviD-LOL.srt
House.S08E13.Man Of The House.mkv

House.S08E14.HDTV.XviD-LOL.srt
House.S08E14.Love Is Blind.mkv

House.S08E15.Blowing The Whistle.mkv
House.S08E15.HDTV.XviD-LOL.srt

House.S08E16.Gut Check.mkv
House.S08E16.HDTV.XviD-LOL.srt

House.S08E17.HDTV.XviD-LOL.srt
House.S08E17.We Need The Eggs.mkv

House.S08E18.Body And Soul.mkv
House.S08E18.HDTV.XviD-LOL.srt

House.S08E19.HDTV.XviD-LOL.srt
House.S08E19.The C Word.mkv

House.S08E20 Post Mortem.mkv
House.S08E20.HDTV.XviD-LOL.srt

House.S08E21.HDTV.XviD-LOL.srt
House.S08E21.Holding On.mkv

House.S08E22.Everybody Dies.mkv
House.S08E22.HDTV.XviD-LOL.srt

House.S08E23.Special-Swan.Song.HDTV.x264-BAJSKORV.srt
House.S08E23.Special-Swan Song.mkv



THAT is what I started with. THIS is after running:

@echo off
cls
for %%a in ("house*.mkv") do (
for /f "tokens=1,2 delims=." %%b in ("%%~a") do (
for %%d in ("%%b.%%c*.srt") do ren "%%~d" "%%~na%%~xd"))



House.S08E01.Twenty Vicodin.mkv
House.S08E01.Twenty Vicodin.srt

House.S08E02.Transplant.mkv
House.S08E02.Transplant.srt

House.S08E03.Charity Case.mkv
House.S08E03.Charity Case.srt

House.S08E04.Risky Business.mkv
House.S08E04.Risky Business.srt

House.S08E05.The Confession.mkv
House.S08E05.The Confession.srt

House.S08E06.Parents.mkv
House.S08E06.Parents.srt

House.S08E07.Dead and Buried.mkv
House.S08E07.Dead and Buried.srt

House.S08E08.Perils of Paranoia.mkv
House.S08E08.Perils of Paranoia.srt

House.S08E09.Better Half.mkv
House.S08E09.Better Half.srt

House.S08E10.Runaways.mkv
House.S08E10.Runaways.srt

House.S08E11.Nobody's Fault.mkv
House.S08E11.Nobody's Fault.srt

House.S08E12.Chase.mkv
House.S08E12.Chase.srt

House.S08E13.Man Of The House.mkv
House.S08E13.Man Of The House.srt

House.S08E14.Love Is Blind.mkv
House.S08E14.Love Is Blind.srt

House.S08E15.Blowing The Whistle.mkv
House.S08E15.Blowing The Whistle.srt

House.S08E16.Gut Check.mkv
House.S08E16.Gut Check.srt

House.S08E17.We Need The Eggs.mkv
House.S08E17.We Need The Eggs.srt

House.S08E18.Body And Soul.mkv
House.S08E18.Body And Soul.srt

House.S08E19.The C Word.mkv
House.S08E19.The C Word.srt

House.S08E20 Post Mortem.mkv
House.S08E20.HDTV.XviD-LOL.srt

House.S08E21.Holding On.mkv
House.S08E21.Holding On.srt

House.S08E22.Everybody Dies.mkv
House.S08E22.Everybody Dies.srt

House.S08E23.Special-Swan Song.mkv
House.S08E23.Special-Swan Song.srt

Thanks for that!
foxidrive
2016-01-20 09:25:04 UTC
Permalink
Post by AlleyCat
Post by foxidrive
Is this project still underway then?
Not at the moment... the script you sent worked perfectly, for THESE
files. Like I said though, at some time I'm going to have files that
aren't so "alike", meaning they will most likely have ONLY the SxxExx in
common, and that is hopeful, but that's USUALLY the standard.
This is quite easy with a batch script called jrepl.bat - See later how to
get that.

When doing this kind of task it can be a mess and a headache if something
goes pear-shaped, so this script creates a temporary-batch-file that will
do the renaming AFTER you check it, and then you run the temporary script
manually.

It creates "+temp.bat.txt" which sorts to the top of the folder usually,
with the plus sign there.

@echo off
set files=*.mkv *.avi *.mov *.mp4 *.mpg
set jrepl=jrepl "(.*)(S[0-9][0-9]E[0-9][0-9])(.*)" "$1|$2|$3" /i /a
(
for %%a in (%files%) do (
for /f "tokens=1-3 delims=|" %%b in ('echo(%%a^|%jrepl%') do (
if exist "*%%c*.srt" echo ren "*%%c*.srt" "%%~na%.srt"
)))>+temp.bat.txt
pause


This uses a native Windows batch script called Jrepl.bat written by
dbenham, which uses jscript to make it very robust and swift.
http://www.dostips.com/forum/viewtopic.php?f=3&t=6044

Place Jrepl.bat in the same folder as the batch file, or in a folder that
is on the system path.


There is also copy on Dropbox (unblock it after downloading):
https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat




This script below creates the sample files that I tested this with - run it
in an empty folder.



@echo off
for %%a in (
"House.S08E01.HDTV.XviD-LOL.srt"
"House.S08E01.Twenty Vicodin.mkv"
"House.S08E02.HDTV.XviD-LOL.srt"
"House.S08E02.Transplant.mkv"
"House.S08E03.Charity Case.mkv"
"House.S08E03.HDTV.XviD-LOL.srt"
"House.S08E04.HDTV.XviD-LOL.srt"
"House.S08E04.Risky Business.mkv"
"House.S08E05.HDTV.XviD-LOL.srt"
"House.S08E05.The Confession.mkv"
"House.S08E06.HDTV.XviD-LOL.srt"
"House.S08E06.Parents.mkv"
"House.S08E07.Dead and Buried.mkv"
"House.S08E07.HDTV.XviD-LOL.srt"
"House.S08E08.HDTV.XviD-LOL.srt"
"House.S08E08.Perils of Paranoia.mkv"
"House.S08E09.Better Half.mkv"
"House.S08E09.HDTV.XviD-LOL.srt"
"House.S08E10.HDTV.XviD-LOL.srt"
"House.S08E10.Runaways.mkv"
"House.S08E11.HDTV.XviD-LOL.srt"
"House.S08E11.Nobody's Fault.mkv"
"House.S08E12.Chase.mkv"
"House.S08E12.HDTV.XviD-LOL.srt"
"House.S08E13.HDTV.XviD-LOL.srt"
"House.S08E13.Man Of The House.mkv"
"House.S08E14.HDTV.XviD-LOL.srt"
"House.S08E14.Love Is Blind.mkv"
"House.S08E15.Blowing The Whistle.mkv"
"House.S08E15.HDTV.XviD-LOL.srt"
"House.S08E16.Gut Check.mkv"
"House.S08E16.HDTV.XviD-LOL.srt"
"House.S08E17.HDTV.XviD-LOL.srt"
"House.S08E17.We Need The Eggs.mkv"
"House.S08E18.Body And Soul.mkv"
"House.S08E18.HDTV.XviD-LOL.srt"
"House.S08E19.HDTV.XviD-LOL.srt"
"House.S08E19.The C Word.mkv"
"House.S08E20 Post Mortem.mkv"
"House.S08E20.HDTV.XviD-LOL.srt"
"House.S08E21.HDTV.XviD-LOL.srt"
"House.S08E21.Holding On.mkv"
"House.S08E22.Everybody Dies.mkv"
"House.S08E22.HDTV.XviD-LOL.srt"
"House.S08E23.Special-Swan.Song.HDTV.x264-BAJSKORV.srt"
"House.S08E23.Special-Swan Song.mkv"
) do break >"%%a"
AlleyCat
2016-01-21 01:20:10 UTC
Permalink
Worked like a charm... thank you!
AlleyCat
2016-01-21 01:42:22 UTC
Permalink
On Wed, 20 Jan 2016 20:25:04 +1100, foxidrive says...
Post by foxidrive
It creates "+temp.bat.txt" which sorts to the top of the folder usually,
with the plus sign there.
@echo off
set files=*.mkv *.avi *.mov *.mp4 *.mpg
set jrepl=jrepl "(.*)(S[0-9][0-9]E[0-9][0-9])(.*)" "$1|$2|$3" /i /a
(
for %%a in (%files%) do (
for /f "tokens=1-3 delims=|" %%b in ('echo(%%a^|%jrepl%') do (
if exist "*%%c*.srt" echo ren "*%%c*.srt" "%%~na%.srt"
)))>+temp.bat.txt
pause
Sorry, I jumped the gun... I renamed the video files, taking out "House"
and left just the SxxExx and the episode name, and the batch file did not
return anything to rename.

S08E15.Blowing The Whistle.mkv
and
House.S08E15.HDTV.XviD-LOL.srt

I was hoping the batch files could scan the folder, find duplicate partial
filenames and rename accordingly.

If ANY of your code needs to NOT look like the above, let me know, since
my newsreader is wrapping the lines at 75 characters.

Thanks.
AlleyCat
2016-01-21 01:45:23 UTC
Permalink
On Wed, 20 Jan 2016 20:25:04 +1100, foxidrive says...
Post by foxidrive
@echo off
set files=*.mkv *.avi *.mov *.mp4 *.mpg
set jrepl=jrepl "(.*)(S[0-9][0-9]E[0-9][0-9])(.*)" "$1|$2|$3" /i /a
(
for %%a in (%files%) do (
for /f "tokens=1-3 delims=|" %%b in ('echo(%%a^|%jrepl%') do (
if exist "*%%c*.srt" echo ren "*%%c*.srt" "%%~na%.srt"
)))>+temp.bat.txt
pause
It seems to be working except when I rename the vid file. I WILL come
across that... vid files named "xxxx.S01E01.mkv" or just S01E01.mkv

Thanks for your help. If i have a problem in future projects, I will call
upon your expertise again.
foxidrive
2016-01-21 03:21:48 UTC
Permalink
Post by AlleyCat
On Wed, 20 Jan 2016 20:25:04 +1100, foxidrive says...
Post by foxidrive
@echo off
set files=*.mkv *.avi *.mov *.mp4 *.mpg
set jrepl=jrepl "(.*)(S[0-9][0-9]E[0-9][0-9])(.*)" "$1|$2|$3" /i /a
(
for %%a in (%files%) do (
for /f "tokens=1-3 delims=|" %%b in ('echo(%%a^|%jrepl%') do (
if exist "*%%c*.srt" echo ren "*%%c*.srt" "%%~na%.srt"
)))>+temp.bat.txt
pause
It seems to be working except when I rename the vid file. I WILL come
across that... vid files named "xxxx.S01E01.mkv" or just S01E01.mkv
Thanks for your help.
No worries. The solution is even simpler.

@echo off
set files=*.mkv *.avi *.mov *.mp4 *.mpg
set jrepl=jrepl ".*(S[0-9][0-9]E[0-9][0-9]).*" "$1" /i /a
(
for %%a in (%files%) do (
for /f %%b in ('echo(%%a^|%jrepl%') do (
if exist "*%%b*.srt" echo ren "*%%b*.srt" "%%~na.srt"
)))>"+.bat.txt"
pause

I tested it with these filenames:

S01E01.mkv
S01E02.srt
xx.S01E01.what a day for a daydream.srt
xxxx.S01E02.mkv

and it gave me this:

S01E01.mkv
S01E01.srt
xxxx.S01E02.mkv
xxxx.S01E02.srt
AlleyCat
2016-01-21 03:38:36 UTC
Permalink
On Thu, 21 Jan 2016 14:21:48 +1100, foxidrive says...
Post by foxidrive
Post by AlleyCat
On Wed, 20 Jan 2016 20:25:04 +1100, foxidrive says...
Post by foxidrive
@echo off
set files=*.mkv *.avi *.mov *.mp4 *.mpg
set jrepl=jrepl "(.*)(S[0-9][0-9]E[0-9][0-9])(.*)" "$1|$2|$3" /i /a
(
for %%a in (%files%) do (
for /f "tokens=1-3 delims=|" %%b in ('echo(%%a^|%jrepl%') do (
if exist "*%%c*.srt" echo ren "*%%c*.srt" "%%~na%.srt"
)))>+temp.bat.txt
pause
It seems to be working except when I rename the vid file. I WILL come
across that... vid files named "xxxx.S01E01.mkv" or just S01E01.mkv
Thanks for your help.
No worries. The solution is even simpler.
@echo off
set files=*.mkv *.avi *.mov *.mp4 *.mpg
set jrepl=jrepl ".*(S[0-9][0-9]E[0-9][0-9]).*" "$1" /i /a
(
for %%a in (%files%) do (
for /f %%b in ('echo(%%a^|%jrepl%') do (
if exist "*%%b*.srt" echo ren "*%%b*.srt" "%%~na.srt"
)))>"+.bat.txt"
pause
S01E01.mkv
S01E02.srt
xx.S01E01.what a day for a daydream.srt
xxxx.S01E02.mkv
S01E01.mkv
S01E01.srt
xxxx.S01E02.mkv
xxxx.S01E02.srt
I'm guessing you didn't try:

Blowing The Whistle.S08E15.mkv

The Sxx.Exx is reversed. I may not have described good enough, what I'm
looking for, but PLEASE, don't work on this any more. What you have given
me is all I can ask for and it works perfectly for the format I have, and
usually get.

For future reference ONLY, I'd like to have a script to change:

Blowing The Whistle.S08E15.mkv or

S08E15.Blowing The Whistle.mkv and

S08E15.HDTV.XviD-LOL.srt or
HDTV.XviD-LOL.S08E15.srt be

Blowing The Whistle.S08E15.srt or
S08E15.Blowing The Whistle.srt

I've tested Blowing The Whistle.S08E15.mkv, as I mentioned above... did
not work.

Maybe jrepl.bat can be tweaked to look for the "Sxx.Exx" ONLY, have YOUR
script set vids *.mkv and rename srt files.

I'm really script stupid, or I'd do it myself.

Again, thanks for all your work... you did goooooood. ;-)

Do you have a donation site?
AlleyCat
2016-01-21 03:41:26 UTC
Permalink
On Thu, 21 Jan 2016 14:21:48 +1100, foxidrive says...
Post by AlleyCat
On Wed, 20 Jan 2016 20:25:04 +1100, foxidrive says...
Works PERFECTLY!! Thanks!
AlleyCat
2016-01-21 03:42:27 UTC
Permalink
On Thu, 21 Jan 2016 14:21:48 +1100, foxidrive says...
Post by AlleyCat
On Wed, 20 Jan 2016 20:25:04 +1100, foxidrive says...
Can this work recursively? Thanks.
AlleyCat
2016-01-21 04:51:46 UTC
Permalink
On Thu, 21 Jan 2016 14:21:48 +1100, foxidrive says...
Post by foxidrive
Post by AlleyCat
It seems to be working except when I rename the vid file. I WILL come
across that... vid files named "xxxx.S01E01.mkv" or just S01E01.mkv
Thanks for your help.
No worries. The solution is even simpler.
Thanks again. I'm downloading subtitles to a (9 season - 196 episode) show
I have on the computer and so far so good.

:-)
foxidrive
2016-01-21 05:43:32 UTC
Permalink
Post by AlleyCat
On Thu, 21 Jan 2016 14:21:48 +1100, foxidrive says...
Post by foxidrive
Post by AlleyCat
Thanks for your help.
No worries. The solution is even simpler.
Thanks again. I'm downloading subtitles to a (9 season - 196 episode) show
I have on the computer and so far so good.
:-)
Jrepl is a great general purpose tool, but this can also be done in a
self-contained script.

The script below uses VBscript inside Windows Scripting Host and no longer
requires Jrepl.bat
- you've been very interested and provided good feedback, which makes the
task so much easier.

It works recursively, and in the same manner as the previous requirements
for the task.
Test it with various files: it's very likely that various filenames with
non-latin characters in them will simply fail to rename.

@echo off
:loop
set "file=%temp%\sarfile-%random%.vbs"
if exist "%file%" goto :loop

set out=regex.replace(wscript.stdin.readall,"$2|$1$2$3")
set "pattern=(.*\\.*)(S[0-9][0-9]E[0-9][0-9])(.*)"
set "global=true"
set "case=false"
Post by AlleyCat
"%file%" echo(set regex=new regexp
Post by foxidrive
"%file%" echo(regex.global=%global%
"%file%" echo(regEx.IgnoreCase=%case%
"%file%" echo(regex.pattern="%pattern%"
"%file%" echo(wscript.stdOut.write %out%
echo(Getting the list of video files
(for /f "delims=" %%a in ('
dir *.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s
') do echo %%a)>"%file%.2"
echo(Processing the list...
(for /f "tokens=1,* delims=|" %%a in ('
cscript /nologo "%file%" ^< "%file%.2"
') do if exist "%%~dpb*%%a*.srt" (
echo(@ren "%%~dpb*%%a*.srt" "%%~nb.srt"))>"+.bat.txt"
echo(done! - check "+.bat.txt" in this folder
del "%file%*"
pause
AlleyCat
2016-01-21 21:47:02 UTC
Permalink
On Thu, 21 Jan 2016 16:43:32 +1100, foxidrive says...
Post by foxidrive
@echo off
:loop
set "file=%temp%\sarfile-%random%.vbs"
if exist "%file%" goto :loop
set out=regex.replace(wscript.stdin.readall,"$2|$1$2$3")
set "pattern=(.*\\.*)(S[0-9][0-9]E[0-9][0-9])(.*)"
set "global=true"
set "case=false"
Post by AlleyCat
"%file%" echo(set regex=new regexp
Post by foxidrive
"%file%" echo(regex.global=%global%
"%file%" echo(regEx.IgnoreCase=%case%
"%file%" echo(regex.pattern="%pattern%"
"%file%" echo(wscript.stdOut.write %out%
echo(Getting the list of video files
(for /f "delims=" %%a in ('
dir *.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s
') do echo %%a)>"%file%.2"
echo(Processing the list...
(for /f "tokens=1,* delims=|" %%a in ('
cscript /nologo "%file%" ^< "%file%.2"
') do if exist "%%~dpb*%%a*.srt" (
echo(done! - check "+.bat.txt" in this folder
del "%file%*"
pause
Awesome! Thanks.

Now, if there was a way to rename ALL formats of srt files, i.e.,

MOST of the time, video files have the SxxExx format in the name, but
there are those who don't conform to convention, ergo, some use the
following formats:

201, 202, 203...

01x01, 01x02, 01x03...

Those would be OK, if the video files were included with the srt's in the
same folder, but I DO get a lot of vids without subtitles, so I have to
download them separately.

I DO have a series or two that have all three types of subtitle formats,
and it IS a pain to have to rename them, but those projects are long over.

Thanks for all of your help!!
foxidrive
2016-01-22 01:21:46 UTC
Permalink
Post by AlleyCat
Now, if there was a way to rename ALL formats of srt files, i.e.,
MOST of the time, video files have the SxxExx format in the name, but
there are those who don't conform to convention, ergo, some use the
201, 202, 203...
01x01, 01x02, 01x03...
Those would be OK, if the video files were included with the srt's in the
same folder, but I DO get a lot of vids without subtitles, so I have to
download them separately.
I DO have a series or two that have all three types of subtitle formats,
and it IS a pain to have to rename them, but those projects are long over.
Thanks for all of your help!!
You know, that's quite doable.

The code below is functionally identical to the one just before - and
getting it to attempt the extra series/episode formats was trivial.


Extra formats can easily be added by duplicating the two lines that start
with the lines below
set "pattern="
"call :routine"

- the "format-01x03" on the call line only determines the filename of the
temporary batch scripts that do the actual renaming.
The "pattern" is a regular expression of the Windows variety, and is the
search term used to identify the right .SRT files for renaming.



Take note of the comments in the script - particularly in regard to the 103
series/episode format.



@echo off
: This creates temporary batch files to rename .SRT files
: to the same filename format as the video files.

: It is recursive in all folders below the current folder,
: and writes temporary batch files with a .txt extension
: into the current folder. eg: "+format-S01E03.bat.txt"

: - it attempts to use the series and episode number
: of the video file, and checks if an .SRT file with the
: same sequence of numbers exists in the same folder.

: If so then it writes a command to rename the .SRT file
: into the temporary batch file.

: *** Check the commands in the temporary batch file ***
: *** before manually running them, as undoing any ***
: *** mistaken renaming could be a headache. ***

: Simply using : at the front of a line will disable that command


: The format 103
: is the most likely to generate incorrect rename commands.



:loop
set "file=%temp%\sarfile-%random%.vbs"
if exist "%file%" goto :loop

set "pattern=(.*\\.*)(S[0-9][0-9]E[0-9][0-9])(.*)"
call :routine format-S01E03

set "pattern=(.*\\.*)([0-9][0-9]x[0-9][0-9])(.*)"
call :routine format-01X03

set "pattern=(.*\\.*)([0-9][0-9][0-9])(.*)"
call :routine format-103


echo(done! - check the "+*.bat.txt" files in "%cd%" folder
del "%file%*"
pause
goto :EOF


:routine
set out=regex.replace(wscript.stdin.readall,"$2|$1$2$3")
set "global=true"
set "case=false"
Post by AlleyCat
"%file%" echo(set regex=new regexp
Post by foxidrive
"%file%" echo(regex.global=%global%
"%file%" echo(regEx.IgnoreCase=%case%
"%file%" echo(regex.pattern="%pattern%"
"%file%" echo(wscript.stdOut.write %out%
echo(Getting the list of video files for %~1

(for /f "delims=" %%a in ('
dir *.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s
') do echo %%a)>"%file%.2"

echo(Processing the %~1 list...

(for /f "tokens=1,* delims=|" %%a in ('
cscript /nologo "%file%" ^< "%file%.2"
') do if exist "%%~dpb*%%a*.srt" (
echo(@ren "%%~dpb*%%a*.srt" "%%~nb.srt"))>"+%~1.bat.txt"
echo(@echo "%~1" renaming done>>"+%~1.bat.txt"
echo(
AlleyCat
2016-01-22 08:46:11 UTC
Permalink
On Fri, 22 Jan 2016 12:21:46 +1100, foxidrive says...
Post by foxidrive
set "pattern=(.*\\.*)(S[0-9][0-9]E[0-9][0-9])(.*)"
call :routine format-S01E03
set "pattern=(.*\\.*)([0-9][0-9]x[0-9][0-9])(.*)"
call :routine format-01X03
set "pattern=(.*\\.*)([0-9][0-9][0-9])(.*)"
call :routine format-103
[shrugging shoulders]

Keep in mind, my newsreader is not concatenating outside of 75±
characters. I hope I used that word right. ;-)

I'm not getting the part in the script, where it's all "103". Help?

Directory contents:
Burn Notice.207.srt
Burn Notice.208.srt
Burn Notice.S02E07.Rough Seas.avi
Burn Notice.S02E08.Double Booked.avi

Here's a twist... I DID have files where the srt file had the episode name
in it, but not the video file. What a super batch that would be, if it
could look for SxxExx in EITHER file, match that up with the various
formats; 207, 02x07 and S02E07 in either file and mirror them.

I'd buy THAT for a dollar.


What batch did:

N:\DVD's\Watched\Burn Notice\Season 2\Test>set "file=H:\Temp\sarfile-
16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>if exist "H:\Temp\sarfile-
16013.vbs" goto :loop

N:\DVD's\Watched\Burn Notice\Season 2\Test>set "pattern=(.*\\.*)(S[0-9][0-
9]E[0-9][0-9])(.*)"

N:\DVD's\Watched\Burn Notice\Season 2\Test>call :routine format-S01E03

N:\DVD's\Watched\Burn Notice\Season 2\Test>set out=regex.replace
(wscript.stdin.readall,"$2|$1$2$3")

N:\DVD's\Watched\Burn Notice\Season 2\Test>set "global=true"

N:\DVD's\Watched\Burn Notice\Season 2\Test>set "case=false"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(set regex=new regexp 1>"H:
\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regex.global=true 1>>"H:
\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regEx.IgnoreCase=false
1>>"H:\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regex.pattern="(.*\\.*)(S
[0-9][0-9]E[0-9][0-9])(.*)" 1>>"H:\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(wscript.stdOut.write
regex.replace(wscript.stdin.readall,"$2|$1$2$3") 1>>"H:\Temp\sarfile-
16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(Getting the list of video
files for format-S01E03
Getting the list of video files for format-S01E03

N:\DVD's\Watched\Burn Notice\Season 2\Test>(for /F "delims=" %a in (' dir
*.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s ') do echo %a ) 1>"H:\Temp
\sarfile-16013.vbs.2"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(Processing the format-
S01E03 list...
Processing the format-S01E03 list...

N:\DVD's\Watched\Burn Notice\Season 2\Test>(for /F "tokens=1,* delims=|" %
a in (' cscript /nologo "H:\Temp\sarfile-16013.vbs" < "H:\Temp\sarfile-
16013.vbs.2" ') do if exist "%~dpb*%a*.srt" (echo(@ren "%~dpb*%a*.srt" "%
~nb.srt" ) ) 1>"+format-S01E03.bat.txt"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(@echo "format-S01E03"
renaming done 1>>"+format-S01E03.bat.txt"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(


N:\DVD's\Watched\Burn Notice\Season 2\Test>set "pattern=(.*\\.*)([0-9][0-
9]x[0-9][0-9])(.*)"

N:\DVD's\Watched\Burn Notice\Season 2\Test>call :routine format-01X03

N:\DVD's\Watched\Burn Notice\Season 2\Test>set out=regex.replace
(wscript.stdin.readall,"$2|$1$2$3")

N:\DVD's\Watched\Burn Notice\Season 2\Test>set "global=true"

N:\DVD's\Watched\Burn Notice\Season 2\Test>set "case=false"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(set regex=new regexp 1>"H:
\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regex.global=true 1>>"H:
\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regEx.IgnoreCase=false
1>>"H:\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regex.pattern="(.*\\.*)
([0-9][0-9]x[0-9][0-9])(.*)" 1>>"H:\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(wscript.stdOut.write
regex.replace(wscript.stdin.readall,"$2|$1$2$3") 1>>"H:\Temp\sarfile-
16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(Getting the list of video
files for format-01X03
Getting the list of video files for format-01X03

N:\DVD's\Watched\Burn Notice\Season 2\Test>(for /F "delims=" %a in (' dir
*.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s ') do echo %a ) 1>"H:\Temp
\sarfile-16013.vbs.2"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(Processing the format-
01X03 list...
Processing the format-01X03 list...

N:\DVD's\Watched\Burn Notice\Season 2\Test>(for /F "tokens=1,* delims=|" %
a in (' cscript /nologo "H:\Temp\sarfile-16013.vbs" < "H:\Temp\sarfile-
16013.vbs.2" ') do if exist "%~dpb*%a*.srt" (echo(@ren "%~dpb*%a*.srt" "%
~nb.srt" ) ) 1>"+format-01X03.bat.txt"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(@echo "format-01X03"
renaming done 1>>"+format-01X03.bat.txt"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(


N:\DVD's\Watched\Burn Notice\Season 2\Test>set "pattern=(.*\\.*)([0-9][0-
9][0-9])(.*)"

N:\DVD's\Watched\Burn Notice\Season 2\Test>call :routine format-103

N:\DVD's\Watched\Burn Notice\Season 2\Test>set out=regex.replace
(wscript.stdin.readall,"$2|$1$2$3")

N:\DVD's\Watched\Burn Notice\Season 2\Test>set "global=true"

N:\DVD's\Watched\Burn Notice\Season 2\Test>set "case=false"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(set regex=new regexp 1>"H:
\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regex.global=true 1>>"H:
\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regEx.IgnoreCase=false
1>>"H:\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(regex.pattern="(.*\\.*)
([0-9][0-9][0-9])(.*)" 1>>"H:\Temp\sarfile-16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(wscript.stdOut.write
regex.replace(wscript.stdin.readall,"$2|$1$2$3") 1>>"H:\Temp\sarfile-
16013.vbs"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(Getting the list of video
files for format-103
Getting the list of video files for format-103

N:\DVD's\Watched\Burn Notice\Season 2\Test>(for /F "delims=" %a in (' dir
*.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s ') do echo %a ) 1>"H:\Temp
\sarfile-16013.vbs.2"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(Processing the format-103
list...
Processing the format-103 list...

N:\DVD's\Watched\Burn Notice\Season 2\Test>(for /F "tokens=1,* delims=|" %
a in (' cscript /nologo "H:\Temp\sarfile-16013.vbs" < "H:\Temp\sarfile-
16013.vbs.2" ') do if exist "%~dpb*%a*.srt" (echo(@ren "%~dpb*%a*.srt" "%
~nb.srt" ) ) 1>"+format-103.bat.txt"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(@echo "format-103"
renaming done 1>>"+format-103.bat.txt"

N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(


N:\DVD's\Watched\Burn Notice\Season 2\Test>echo(done! - check the
"+*.bat.txt" files in "N:\DVD's\Watched\Burn Notice\Season 2\Test" folder
done! - check the "+*.bat.txt" files in "N:\DVD's\Watched\Burn Notice
\Season 2\Test" folder

N:\DVD's\Watched\Burn Notice\Season 2\Test>del "H:\Temp\sarfile-
16013.vbs*"

N:\DVD's\Watched\Burn Notice\Season 2\Test>goto :EOF
AlleyCat
2016-01-22 08:54:28 UTC
Permalink
On Fri, 22 Jan 2016 12:21:46 +1100, foxidrive says...
Post by foxidrive
set "pattern=(.*\\.*)(S[0-9][0-9]E[0-9][0-9])(.*)"
call :routine format-S01E03
set "pattern=(.*\\.*)([0-9][0-9]x[0-9][0-9])(.*)"
call :routine format-01X03
set "pattern=(.*\\.*)([0-9][0-9][0-9])(.*)"
call :routine format-103
Sorry... cleaned up a bit to read easier.

Directory contents:
Burn Notice.207.srt
Burn Notice.208.srt
Burn Notice.S02E07.Rough Seas.avi
Burn Notice.S02E08.Double Booked.avi


echo(Getting the list of video files for format-S01E03

Shouldn't that be *S??E??* or some derivation of?

I get lost after set. LOL


set "file=H:\Temp\sarfile-16013.vbs"

if exist "H:\Temp\sarfile-16013.vbs" goto :loop

set "pattern=(.*\\.*)(S[0-9][0-9]E[0-9][0-9])(.*)"

call :routine format-S01E03

set out=regex.replace(wscript.stdin.readall,"$2|$1$2$3")

set "global=true"

set "case=false"

echo(set regex=new regexp 1>"H:\Temp\sarfile-16013.vbs"

echo(regex.global=true 1>>"H:\Temp\sarfile-16013.vbs"

echo(regEx.IgnoreCase=false 1>>"H:\Temp\sarfile-16013.vbs"

echo(regex.pattern="(.*\\.*)(S[0-9][0-9]E[0-9][0-9])(.*)" 1>>"H:\Temp
\sarfile-16013.vbs"

echo(wscript.stdOut.write regex.replace(wscript.stdin.readall,"$2|$1$2$3")
1>>"H:\Temp\sarfile-16013.vbs"

echo(Getting the list of video files for format-S01E03
Getting the list of video files for format-S01E03

(for /F "delims=" %a in (' dir *.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s ')
do echo %a ) 1>"H:\Temp\sarfile-16013.vbs.2"

echo(Processing the format-S01E03 list...
Processing the format-S01E03 list...

(for /F "tokens=1,* delims=|" %a in (' cscript /nologo "H:\Temp\sarfile-
16013.vbs" < "H:\Temp\sarfile-16013.vbs.2" ') do if exist "%~dpb*%a*.srt"
(echo(@ren "%~dpb*%a*.srt" "%~nb.srt" ) ) 1>"+format-S01E03.bat.txt"

echo(@echo "format-S01E03" renaming done 1>>"+format-S01E03.bat.txt"

echo(


set "pattern=(.*\\.*)([0-9][0-9]x[0-9][0-9])(.*)"

call :routine format-01X03

set out=regex.replace(wscript.stdin.readall,"$2|$1$2$3")

set "global=true"

set "case=false"

echo(set regex=new regexp 1>"H:\Temp\sarfile-16013.vbs"

echo(regex.global=true 1>>"H:\Temp\sarfile-16013.vbs"

echo(regEx.IgnoreCase=false 1>>"H:\Temp\sarfile-16013.vbs"

echo(regex.pattern="(.*\\.*)([0-9][0-9]x[0-9][0-9])(.*)" 1>>"H:\Temp
\sarfile-16013.vbs"

echo(wscript.stdOut.write regex.replace(wscript.stdin.readall,"$2|$1$2$3")
1>>"H:\Temp\sarfile-16013.vbs"

echo(Getting the list of video files for format-01X03
Getting the list of video files for format-01X03

(for /F "delims=" %a in (' dir *.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s ')
do echo %a ) 1>"H:\Temp\sarfile-16013.vbs.2"

echo(Processing the format-01X03 list...
Processing the format-01X03 list...

(for /F "tokens=1,* delims=|" %a in (' cscript /nologo "H:\Temp\sarfile-
16013.vbs" < "H:\Temp\sarfile-16013.vbs.2" ') do if exist "%~dpb*%a*.srt"
(echo(@ren "%~dpb*%a*.srt" "%~nb.srt" ) ) 1>"+format-01X03.bat.txt"

echo(@echo "format-01X03" renaming done 1>>"+format-01X03.bat.txt"

echo(


set "pattern=(.*\\.*)([0-9][0-9][0-9])(.*)"

call :routine format-103

set out=regex.replace(wscript.stdin.readall,"$2|$1$2$3")

set "global=true"

set "case=false"

echo(set regex=new regexp 1>"H:\Temp\sarfile-16013.vbs"

echo(regex.global=true 1>>"H:\Temp\sarfile-16013.vbs"

echo(regEx.IgnoreCase=false 1>>"H:\Temp\sarfile-16013.vbs"

echo(regex.pattern="(.*\\.*)([0-9][0-9][0-9])(.*)" 1>>"H:\Temp\sarfile-
16013.vbs"

echo(wscript.stdOut.write regex.replace(wscript.stdin.readall,"$2|$1$2$3")
1>>"H:\Temp\sarfile-16013.vbs"

echo(Getting the list of video files for format-103
Getting the list of video files for format-103

(for /F "delims=" %a in (' dir *.mkv *.avi *.mov *.mp4 *.mpg /b /a-d /s ')
do echo %a ) 1>"H:\Temp\sarfile-16013.vbs.2"

echo(Processing the format-103 list...
Processing the format-103 list...

(for /F "tokens=1,* delims=|" %a in (' cscript /nologo "H:\Temp\sarfile-
16013.vbs" < "H:\Temp\sarfile-16013.vbs.2" ') do if exist "%~dpb*%a*.srt"
(echo(@ren "%~dpb*%a*.srt" "%~nb.srt" ) ) 1>"+format-103.bat.txt"

echo(@echo "format-103" renaming done 1>>"+format-103.bat.txt"

echo(


echo(done! - check the "+*.bat.txt" files in "N:\DVD's\Watched\Burn Notice
\Season 2\Test" folder
done! - check the "+*.bat.txt" files in "N:\DVD's\Watched\Burn Notice
\Season 2\Test" folder

del "H:\Temp\sarfile-16013.vbs*"

goto :EOF
foxidrive
2016-01-22 09:05:42 UTC
Permalink
Post by AlleyCat
On Fri, 22 Jan 2016 12:21:46 +1100, foxidrive says...
Post by foxidrive
set "pattern=(.*\\.*)(S[0-9][0-9]E[0-9][0-9])(.*)"
call :routine format-S01E03
set "pattern=(.*\\.*)([0-9][0-9]x[0-9][0-9])(.*)"
call :routine format-01X03
set "pattern=(.*\\.*)([0-9][0-9][0-9])(.*)"
call :routine format-103
Sorry... cleaned up a bit to read easier.
Burn Notice.207.srt
Burn Notice.208.srt
Burn Notice.S02E07.Rough Seas.avi
Burn Notice.S02E08.Double Booked.avi
echo(Getting the list of video files for format-S01E03
Shouldn't that be *S??E??* or some derivation of?
Without commenting on the example of a format string - what did the code do
to your files that is the problem?
Can you paste the rename commands in the files?

The cmd prompt output without echo off is unwieldy to browse through here,
without knowing what problem there may be. :)


The format string shown is just an example of the sort of string it will
look for.
EG: "103" is an example of the types you showed such as 203 204 205 206 etc
and also 103 108 403 703 etc.


The filenames you have shown match two type of file formats and neither of
the sets will match.
AlleyCat
2016-01-22 22:55:44 UTC
Permalink
On Fri, 22 Jan 2016 20:05:42 +1100, foxidrive says...
Post by foxidrive
Without commenting on the example of a format string - what did the code
do to your files that is the problem?
Nothing. No changes. All of the output bat files were to rename 103, 01x03
and S01E03. There were no files by those names.
Post by foxidrive
Can you paste the rename commands in the files?
+format-01X03.bat.txt
@echo "format-01X03" renaming done

+format-103.bat.txt
@echo "format-103" renaming done

+format-S01E03.bat.txt
@echo "format-S01E03" renaming done

Files in folder:
Burn Notice.207.srt
Burn Notice.208.srt
Burn Notice.S02E07.Rough Seas.avi
Burn Notice.S02E08.Double Booked.avi
Post by foxidrive
The cmd prompt output without echo off is unwieldy to browse through here,
without knowing what problem there may be. :)
********************************************************************
Getting the list of video files for format-S01E03
Processing the format-S01E03 list...

Getting the list of video files for format-01X03
Processing the format-01X03 list...

Getting the list of video files for format-103
Processing the format-103 list...

done! - check the "+*.bat.txt" files in "N:\DVD's\Watched\Burn Notice
\Season 2\Test" folder

*********************************************************************
Post by foxidrive
The format string shown is just an example of the sort of string it will
look for.
EG: "103" is an example of the types you showed such as 203 204 205 206 etc
and also 103 108 403 703 etc.
The filenames you have shown match two type of file formats and neither of
the sets will match.
foxidrive
2016-01-23 03:43:25 UTC
Permalink
Post by AlleyCat
Burn Notice.207.srt
Burn Notice.208.srt
Burn Notice.S02E07.Rough Seas.avi
Burn Notice.S02E08.Double Booked.avi
Thanks for the pastes and info AlleyCat.

The following line was meant to indicate that it only writes the rename
commands if the same series/episode format is inside the two files. I
didn't follow that your files can mix any of the three formats.
Post by AlleyCat
The filenames you have shown match two type of file formats and neither of the sets will match.
It's easy to make it stop creating the files if no rename commands are inside.
Post by AlleyCat
[shrugging shoulders]
I'm not getting the part in the script, where it's all "103". Help?
Did I explain the 103 enough to understand? If I didn't, then ask for
clarification of the part you misunderstand.
AlleyCat
2016-01-23 05:37:04 UTC
Permalink
On Sat, 23 Jan 2016 14:43:25 +1100, foxidrive says...
Post by foxidrive
Post by AlleyCat
Burn Notice.207.srt
Burn Notice.208.srt
Burn Notice.S02E07.Rough Seas.avi
Burn Notice.S02E08.Double Booked.avi
Thanks for the pastes and info AlleyCat.
The following line was meant to indicate that it only writes the rename
commands if the same series/episode format is inside the two files. I
didn't follow that your files can mix any of the three formats.
Post by AlleyCat
The filenames you have shown match two type of file formats and neither of the sets will match.
It's easy to make it stop creating the files if no rename commands are inside.
Post by AlleyCat
[shrugging shoulders]
I'm not getting the part in the script, where it's all "103". Help?
Did I explain the 103 enough to understand? If I didn't, then ask for
clarification of the part you misunderstand.
There was no renaming. If you can write the file to rename these:

Burn Notice.207.srt
Burn Notice.208.srt
Burn Notice.S02E07.Rough Seas.avi
Burn Notice.S02E08.Double Booked.avi

... go ahead and rename them. I always have a backup of EVERYTHING!! LOL

I'm a backupaholic. It's simple, but effective. ;-)

@echo off
cls
:Restart
:Begin
cls
echo.
echo Backup (N)Drive to J, (A)ll, (D)Drive,(H)Drive,(B)oth or (E)xit
choice /c:DHBJEARN
rem /t:E,10
if errorlevel 8 goto N
if errorlevel 7 goto RFF
if errorlevel 6 goto All
if errorlevel 5 goto End
if errorlevel 4 goto J
if errorlevel 3 goto Both
if errorlevel 2 goto H
if errorlevel 1 goto D

:All
CLS
echo Backing Up D: Drive to N: Drive
Robocopy D:\ N:\ /S /E /Z /B /ZB /XO /XX /XD Temp /XD tmp /XF PAGEFILE.SYS
/R:1 /W:1 /ETA
be delay 60
rem *.GHO /XF *.GHS
echo.
echo Backing Up H: Drive to N: Drive
be delay 18
Robocopy H:\ N:\ /S /E /Z /B /ZB /XO /XX /XD Temp /XD tmp /XD Watched /R:1
/W:1 /ETA
rem /XD Temp /XD tmp
playmedia "c:\windows\media\dataxfer.mp3"
GOTO End

:H
cls
echo.
echo Backing Up H: Drive to N: Drive
echo.
Robocopy H:\ N:\ /S /E /Z /B /ZB /XO /XX /XD Temp /XD tmp /XD Watched /R:1
/W:1 /ETA
goto Begin

:N
cls
echo.
if not exist J:\Dummy_file.txt goto Begin
echo Backing Up N: Drive to J: USB_Drive
echo.

Robocopy N:\MP3's J:\MP3's /S /E /Z /B /ZB /R:2 /W:2 /ETA
Robocopy N:\DVD's J:\DVD's /S /E /Z /B /ZB /R:2 /W:2 /ETA

rem cmdow "Backup D Drive" /min
playmedia "c:\windows\media\dataxfer.wav"
goto Begin

cls

if exist K:\*.* goto N2K
if not exist K:\Dummy_file.txt goto Timer

:N2K
N:
cd\
cls
echo.
echo Backing Up N: Drive to USB K: Drive
echo.
xcopy /i/s/d/c/y *.* K:\
cmdow "Backup D Drive" /min
rem /exclude: D:\download\donotcopy.txt

cls
echo.
echo Transfer of Data Is Complete
echo.
echo Please Remove USB Drive
be delay 100
cls
playmedia "c:\windows\media\dataxfer.wAV"
cls

:D
cls
echo Copying D: Drive to H: Drive
Robocopy D:\ H:\ /S /E /Z /B /ZB /XO /XX /XD Temp /XD tmp /XF PAGEFILE.SYS
/R:1 /W:1 /ETA
Robocopy D:\ N:\ /S /E /Z /B /ZB /XO /XX /XD Temp /XD tmp /XF PAGEFILE.SYS
/R:1 /W:1 /ETA

:J
Robocopy J:\ N:\ /S /E /Z /B /ZB /XX /XD Temp /XD tmp /XF PAGEFILE.SYS
/R:1 /W:1 /ETA
goto Begin

:Shutdown
cmdow "Backup D Drive" /max
cmdow "Backup D Drive" /ACT
cmdow "Backup D Drive" /ACT
cls
echo Transfer of DATA is Complete!
rem be delay 9
playmedia "c:\windows\media\dataxfer.wAV"
cmdow "Backup D Drive" /max
cmdow "Backup D Drive" /ACT
cmdow "Backup D Drive" /ACT
echo.
echo Transfer of DATA is Complete!
cls
echo.
echo You Have 10 Seconds to Abort Standby
echo.
echo Sta(n)dby (Do Nothing), (S)hutdown, (A)bort, (R)estart Computer or
(B)egin Backing Up Hard Drive?
choice /c:NARSB /T:N,10
if errorlevel 5 goto Begin
if errorlevel 4 goto Shutdown Computer
if errorlevel 3 goto Restart Computer
if errorlevel 2 goto End
if errorlevel 1 goto Standby

:Standby
mplay32 /play /close "c:\windows\media\autoshut2.wAV"
be delay 180
be beep
be delay 18
be beep
be delay 18
be beep
be delay 18
be beep
cls
echo You Have 10 Seconds to Cancel Standby "Close Window Now"
be delay 180
echo REALLY Close Program? YOu Have 10 Seconds to Comply
choice /C:YN /t:N,10
if errorlevel 2 goto End
rundll32.exe user32.dll,LockWorkStation
%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState
goto Begin

:Shutdown Computer
cmdow "Backup D Drive" /max
cmdow "Backup D Drive" /ACT
mplay32 /play /close "c:\windows\media\autoshut2.wAV"
%windir%\system32\shutdown.exe -s -t 10

:Restart Computer
mplay32 /play /close "c:\windows\media\autoshut2.wAV"
%windir%\system32\shutdown.exe -r -t 10
goto Restart

:End
Todd Vargo
2016-01-20 03:53:25 UTC
Permalink
Post by AlleyCat
On Mon, 18 Jan 2016 23:26:49 -0500, Todd Vargo says...
Post by Todd Vargo
S08E18 does not match S08E03. Originally, you posted matching examples.
Now they don't match. Did you make a typo in this Subtitle example?
LOL... yes. I was copying pasting and wanted to use a different example
than S08E18, and forgot to use the srt version of S08E03.
Sorry.
Todd, do you think it's possible for a batch file/script to search a
folder and see like files and rename the srt to match the mkv?
Hell, I'd settle for a mini program compiled to do it. I've got a friend
who writes code, but he's too busy with his life. LOL
I wouldn't hazard to guess based on the few filenames provided so far.
With a more extensive list it might be possible to provide one with some
degree of reliability.

In your example
:
House.S08E18.Body And Soul.mkv



Is the .SxxExx. part always the second token?

Will the first token (House) always be a single word?

Did the code from either foxi or JJ do everything that you needed? If
not, what issues are you experiencing?


The following is a single line that may do what you want based solely on
what is known so far. The ECHO disables the rename command. If the
output looks correct, remove the ECHO to enable. I suggest you test it
on a test folder first.

for %a in (*.S??E??.*.mkv) do for /f "tokens=1-2 delims=." %A in ("%a")
do ECHO ren "%A.%B.*.srt" "%~na.srt"
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
AlleyCat
2016-01-20 08:11:35 UTC
Permalink
On Tue, 19 Jan 2016 22:53:25 -0500, Todd Vargo says...
Post by Todd Vargo
I wouldn't hazard to guess based on the few filenames provided so far.
With a more extensive list it might be possible to provide one with some
degree of reliability.
In your example
House.S08E18.Body And Soul.mkv
Is the .SxxExx. part always the second token?
No... if at all possible, I need the script to look for the SxxExx of all
files and then match up the "like" files, one .vid and one .srt, THEN
rename the .srt to match the .vid name exactly, other than the extension.
Post by Todd Vargo
Will the first token (House) always be a single word?
No. There might not even BE a "token". It's need to match the SxxExx's up.

Here is the contents of the folder "as is", before I ran foxidrive's
script.

House.S08E01.HDTV.XviD-LOL.srt
House.S08E01.Twenty Vicodin.mkv

House.S08E02.HDTV.XviD-LOL.srt
House.S08E02.Transplant.mkv

House.S08E03.Charity Case.mkv
House.S08E03.HDTV.XviD-LOL.srt

House.S08E04.HDTV.XviD-LOL.srt
House.S08E04.Risky Business.mkv

House.S08E05.HDTV.XviD-LOL.srt
House.S08E05.The Confession.mkv

House.S08E06.HDTV.XviD-LOL.srt
House.S08E06.Parents.mkv

House.S08E07.Dead and Buried.mkv
House.S08E07.HDTV.XviD-LOL.srt

House.S08E08.HDTV.XviD-LOL.srt
House.S08E08.Perils of Paranoia.mkv

House.S08E09.Better Half.mkv
House.S08E09.HDTV.XviD-LOL.srt

House.S08E10.HDTV.XviD-LOL.srt
House.S08E10.Runaways.mkv

House.S08E11.HDTV.XviD-LOL.srt
House.S08E11.Nobody's Fault.mkv

House.S08E12.Chase.mkv
House.S08E12.HDTV.XviD-LOL.srt

House.S08E13.HDTV.XviD-LOL.srt
House.S08E13.Man Of The House.mkv

House.S08E14.HDTV.XviD-LOL.srt
House.S08E14.Love Is Blind.mkv

House.S08E15.Blowing The Whistle.mkv
House.S08E15.HDTV.XviD-LOL.srt

House.S08E16.Gut Check.mkv
House.S08E16.HDTV.XviD-LOL.srt

House.S08E17.HDTV.XviD-LOL.srt
House.S08E17.We Need The Eggs.mkv

House.S08E18.Body And Soul.mkv
House.S08E18.HDTV.XviD-LOL.srt

House.S08E19.HDTV.XviD-LOL.srt
House.S08E19.The C Word.mkv

House.S08E20 Post Mortem.mkv
House.S08E20.HDTV.XviD-LOL.srt

House.S08E21.HDTV.XviD-LOL.srt
House.S08E21.Holding On.mkv

House.S08E22.Everybody Dies.mkv
House.S08E22.HDTV.XviD-LOL.srt

House.S08E23.Special-Swan.Song.HDTV.x264-BAJSKORV.srt
House.S08E23.Special-Swan Song.mkv

***************************

At some time I'm going to have files that aren't so "alike", meaning they
will most likely have ONLY the SxxExx in common, and that is hopeful, but
that's USUALLY the standard.

This could be the video file: House.S08E11.Nobody's Fault.xxx
And this could be the subtitle file: S08E11.House.srt

I would need for the script to find "x", x being the SxxExx, and rename
the srt file to match the vid file.

***************************

THIS is after running:

@echo off
cls
for %%a in ("house*.mkv") do (
for /f "tokens=1,2 delims=." %%b in ("%%~a") do (
for %%d in ("%%b.%%c*.srt") do ren "%%~d" "%%~na%%~xd"))

House.S08E01.Twenty Vicodin.mkv
House.S08E01.Twenty Vicodin.srt

House.S08E02.Transplant.mkv
House.S08E02.Transplant.srt

House.S08E03.Charity Case.mkv
House.S08E03.Charity Case.srt

House.S08E04.Risky Business.mkv
House.S08E04.Risky Business.srt

House.S08E05.The Confession.mkv
House.S08E05.The Confession.srt

House.S08E06.Parents.mkv
House.S08E06.Parents.srt

House.S08E07.Dead and Buried.mkv
House.S08E07.Dead and Buried.srt

House.S08E08.Perils of Paranoia.mkv
House.S08E08.Perils of Paranoia.srt

House.S08E09.Better Half.mkv
House.S08E09.Better Half.srt

House.S08E10.Runaways.mkv
House.S08E10.Runaways.srt

House.S08E11.Nobody's Fault.mkv
House.S08E11.Nobody's Fault.srt

House.S08E12.Chase.mkv
House.S08E12.Chase.srt

House.S08E13.Man Of The House.mkv
House.S08E13.Man Of The House.srt

House.S08E14.Love Is Blind.mkv
House.S08E14.Love Is Blind.srt

House.S08E15.Blowing The Whistle.mkv
House.S08E15.Blowing The Whistle.srt

House.S08E16.Gut Check.mkv
House.S08E16.Gut Check.srt

House.S08E17.We Need The Eggs.mkv
House.S08E17.We Need The Eggs.srt

House.S08E18.Body And Soul.mkv
House.S08E18.Body And Soul.srt

House.S08E19.The C Word.mkv
House.S08E19.The C Word.srt

House.S08E20 Post Mortem.mkv
House.S08E20.HDTV.XviD-LOL.srt

House.S08E21.Holding On.mkv
House.S08E21.Holding On.srt

House.S08E22.Everybody Dies.mkv
House.S08E22.Everybody Dies.srt

House.S08E23.Special-Swan Song.mkv
House.S08E23.Special-Swan Song.srt
Post by Todd Vargo
Did the code from either foxi or JJ do everything that you needed? If
not, what issues are you experiencing?
What foxi sent worked well, but...
Post by Todd Vargo
The following is a single line that may do what you want based solely on
what is known so far. The ECHO disables the rename command. If the
output looks correct, remove the ECHO to enable. I suggest you test it
on a test folder first.
for %a in (*.S??E??.*.mkv) do for /f "tokens=1-2 delims=." %A in ("%a")
do ECHO ren "%A.%B.*.srt" "%~na.srt"
A was unexpected at this time.

H:\DVD's\House Season 8\Test>for A in ("A.~na.srt"

H:\DVD's\House Season 8\Test>test

Thanks.
Todd Vargo
2016-01-21 03:28:16 UTC
Permalink
Post by AlleyCat
On Tue, 19 Jan 2016 22:53:25 -0500, Todd Vargo says...
<snip>
Post by AlleyCat
Post by Todd Vargo
The following is a single line that may do what you want based solely on
what is known so far. The ECHO disables the rename command. If the
output looks correct, remove the ECHO to enable. I suggest you test it
on a test folder first.
for %a in (*.S??E??.*.mkv) do for /f "tokens=1-2 delims=." %A in ("%a")
do ECHO ren "%A.%B.*.srt" "%~na.srt"
A was unexpected at this time.
H:\DVD's\House Season 8\Test>for A in ("A.~na.srt"
H:\DVD's\House Season 8\Test>test
The single line was intended to be run from the command line. To use in
a batch file you must first double all of the % symbols.

Anyway, it looks like foxi has the new format covered so I'm done.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
AlleyCat
2016-01-21 03:43:07 UTC
Permalink
On Wed, 20 Jan 2016 22:28:16 -0500, Todd Vargo says...
Post by Todd Vargo
Post by AlleyCat
On Tue, 19 Jan 2016 22:53:25 -0500, Todd Vargo says...
<snip>
Post by AlleyCat
Post by Todd Vargo
The following is a single line that may do what you want based solely on
what is known so far. The ECHO disables the rename command. If the
output looks correct, remove the ECHO to enable. I suggest you test it
on a test folder first.
for %a in (*.S??E??.*.mkv) do for /f "tokens=1-2 delims=." %A in ("%a")
do ECHO ren "%A.%B.*.srt" "%~na.srt"
A was unexpected at this time.
H:\DVD's\House Season 8\Test>for A in ("A.~na.srt"
H:\DVD's\House Season 8\Test>test
The single line was intended to be run from the command line. To use in
a batch file you must first double all of the % symbols.
Anyway, it looks like foxi has the new format covered so I'm done.
Thanks Todd. Can always count on you.
JJ
2016-01-18 15:39:59 UTC
Permalink
Post by AlleyCat
Hello all. I think this will be simple for you batch and script gurus, but
it's driving me crazy.
Videofile: House.S08E18.Body And Soul.mkv
Subtitle: House.S08E18.HDTV.XviD-LOL.srt
If you please... copy text after third period (or whatever will be before
the extension in other cases) of videofile and copy it to the srt file, so
both files are identical other than the extension.
Sample: House.S08E18.Body And Soul.mkv
House.S08E18.Body And Soul.srt
Not all vid files are in this "format", but I'll work on it from there.
Thank you so very much.
It's pretty complicated considering the format can be anything. Try below
code. Use code from the pastebin link if your news client always split long
lines.

<http://pastebin.com/4Ajrgiak>

The code relies heavily on the well known episode numbering format "SxxEyy".
It must be in the proper numbers. e.g. no season/episode zero. It assumes
that the text before that is the video title. It'll use both as a prefix
with period or a space separator based file naming. Text after the episode
are ignored. If two or more video files matched, only the first one is used.

e.g. for these files:

House S08E18 Body And Soul.mkv
House.S08E18.HDTV.XviD-LOL.srt
House.S08E18.Body And Soul.H264-LMAO.mkv
House.S08E18.HDTV.XviD-LOL.srt

The srt will be renamed as:

House S08E18 Body And Soul.srt

The actual REN command in the batch file is disabled. It simply show the REN
command line that should be executed.


@echo off
setlocal enabledelayedexpansion
pushd
if "%~1" == "" (
echo Usage: SyncSrtFileNames {folder}
goto :eof
)
cd /d "%~1"
if not errorlevel 0 (
echo Path is not accessible.
goto :eof
)
for %%A in (*.srt) do (
set fname=%%A
set fext=%%~xA
set processed=0
for /f "tokens=1-30 delims=." %%B in ("%%A") do (
call :getprefix "%%B" "%%C" "%%D" "%%E" "%%F" "%%G" "%%H" "%%I" "%%J"
"%%K" "%%L" "%%M" "%%N" "%%O" "%%P" "%%Q" "%%R" "%%S" "%%T" "%%U" "%%V"
"%%W" "%%X" "%%Y" "%%Z" "%%[" "%%\" "%%]" "%%^^" "%%_"
)
if !processed! == 0 (
for /f "tokens=1-30 delims= " %%B in ("%%A") do (
call :getprefix "%%B" "%%C" "%%D" "%%E" "%%F" "%%G" "%%H" "%%I" "%%J"
"%%K" "%%L" "%%M" "%%N" "%%O" "%%P" "%%Q" "%%R" "%%S" "%%T" "%%U" "%%V"
"%%W" "%%X" "%%Y" "%%Z" "%%[" "%%\" "%%]" "%%^^" "%%_"
)
)
)
goto :eof

:getprefix
set eps=
set prefix=
set separator=.
call :gploop %*
set eps=
set prefix=
set "separator= "
call :gploop %*
goto :eof

:gploop
if "%~1" == "" goto :eof
set ch=%~1
call :chkeps %ch:~0,1% %ch:~1,1% %ch:~2,1% %ch:~3,1% %ch:~4,1% %ch:~5,1%
%ch:~6,1%
if "%prefix%" == "" (
set prefix=%~1
) else (
set prefix=%prefix%%separator%%~1
)
if not "%eps%" == "" (
if not "%prefix%" == "" (
for %%B in ("%prefix%*") do (
if !processed! == 0 if not "%%~B" == "%fname%" (
echo dummy: ren "%fname%" "%%~nB%!fext!"
set processed=1
)
)
)
goto :eof
)
shift
goto :gploop

:chkeps
if not "%7" == "" goto :eof
if /i not "%1" == "s" goto :eof
set /a num=(%2*10)+%3
if !num! == 0 goto :eof
if /i not "%4" == "e" goto :eof
set /a num=(%5*10)+%6
if !num! == 0 goto :eof
set eps=%ch%
AlleyCat
2016-01-18 22:26:07 UTC
Permalink
On Mon, 18 Jan 2016 22:39:59 +0700, JJ says...
Post by JJ
Post by AlleyCat
Hello all. I think this will be simple for you batch and script gurus, but
it's driving me crazy.
Videofile: House.S08E18.Body And Soul.mkv
Subtitle: House.S08E18.HDTV.XviD-LOL.srt
If you please... copy text after third period (or whatever will be before
the extension in other cases) of videofile and copy it to the srt file, so
both files are identical other than the extension.
Sample: House.S08E18.Body And Soul.mkv
House.S08E18.Body And Soul.srt
Not all vid files are in this "format", but I'll work on it from there.
Thank you so very much.
It's pretty complicated considering the format can be anything. Try below
code. Use code from the pastebin link if your news client always split long
lines.
<http://pastebin.com/4Ajrgiak>
The code relies heavily on the well known episode numbering format "SxxEyy".
It must be in the proper numbers. e.g. no season/episode zero. It assumes
that the text before that is the video title. It'll use both as a prefix
with period or a space separator based file naming. Text after the episode
are ignored. If two or more video files matched, only the first one is used.
House S08E18 Body And Soul.mkv
House.S08E18.HDTV.XviD-LOL.srt
House.S08E18.Body And Soul.H264-LMAO.mkv
House.S08E18.HDTV.XviD-LOL.srt
House S08E18 Body And Soul.srt
The actual REN command in the batch file is disabled. It simply show the REN
command line that should be executed.
Wow... thank you very much!
Zaidy036
2022-01-10 22:42:26 UTC
Permalink
Post by AlleyCat
Hello all. I think this will be simple for you batch and script gurus, but
it's driving me crazy.
Videofile: House.S08E18.Body And Soul.mkv
Subtitle: House.S08E18.HDTV.XviD-LOL.srt
If you please... copy text after third period (or whatever will be before
the extension in other cases) of videofile and copy it to the srt file, so
both files are identical other than the extension.
Sample: House.S08E18.Body And Soul.mkv
House.S08E18.Body And Soul.srt
Not all vid files are in this "format", but I'll work on it from there.
Thank you so very much.
Substitution works for you:

SET Title="House.S08E18.Body And Soul.mkv"
SET Title2="%Title:~0,-3%srt
then
Echo Title2
gives
House.S08E18.Body And Soul.srt

Loading...