Page 1 of 1

can you help me to rename a bunch of srt files?

Posted: 02 Aug 2014 19:04
by giuliastar
hi

well i have movies in mp4
for example
01_01-why.mp4
01_02-importing.mp4


and the subtitles
01. Why you should watch this fast-track chapter.srt
02. Importing media.srt
is there a way to rename these srt ? for example

Code: Select all

01. Why you should watch this fast-track chapter.srt
to

Code: Select all

01_01-why.srt
seeing i have lot's of srt files to rename , how can i do it?
thanks

Re: can you help me to rename a bunch of srt files?

Posted: 02 Aug 2014 20:12
by highend
Sure (by scripting). But in a reliable way only if the (second) leading numbers are really unique.

E.g.:
01_01-why.mp4

If there is any other file beginning with
01_01-whatever.mp4

You'd run into trouble.

So... Leading numbers are unique? Are the .srt files in the same folder as the .mp4 files?

Re: can you help me to rename a bunch of srt files?

Posted: 02 Aug 2014 20:22
by giuliastar
highend wrote:Sure (by scripting). But in a reliable way only if the (second) leading numbers are really unique.

E.g.:
01_01-why.mp4

If there is any other file beginning with
01_01-whatever.mp4

You'd run into trouble.

So... Leading numbers are unique? Are the .srt files in the same folder as the .mp4 files?
hi
thanks for the answer
yes the srt are in the same mp4 folders

Re: can you help me to rename a bunch of srt files?

Posted: 02 Aug 2014 20:31
by highend

Code: Select all

    $srtFiles = listfolder("<curpath>", "*.srt", 5, "<crlf>");
    $movieFiles = listfolder("<curpath>", "*.mp4", 5, "<crlf>");
    foreach($file, $movieFiles, "<crlf>") {
        $baseName = getpathcomponent($file, "base");
        $ndleading = regexreplace($file, "(^\d+_)(\d+)(-.*)", "$2");
        $match = regexmatches($srtFiles, "$ndleading.*?(?=$)");
        if (gettoken($match, "count", "|") == 1) {
            renameitem($baseName, $match);
        }
    }
Go into the folder that contains the .mp4 and .srt files and execute the above script.
It renames only those files for which it finds a unique match (based on the second leading number of the .mp4 file name).

Ofc you should test it with a copy of your files (a few would be enough) first!

Re: can you help me to rename a bunch of srt files?

Posted: 03 Aug 2014 06:48
by giuliastar
highend wrote:

Code: Select all

    $srtFiles = listfolder("<curpath>", "*.srt", 5, "<crlf>");
    $movieFiles = listfolder("<curpath>", "*.mp4", 5, "<crlf>");
    foreach($file, $movieFiles, "<crlf>") {
        $baseName = getpathcomponent($file, "base");
        $ndleading = regexreplace($file, "(^\d+_)(\d+)(-.*)", "$2");
        $match = regexmatches($srtFiles, "$ndleading.*?(?=$)");
        if (gettoken($match, "count", "|") == 1) {
            renameitem($baseName, $match);
        }
    }
Go into the folder that contains the .mp4 and .srt files and execute the above script.
It renames only those files for which it finds a unique match (based on the second leading number of the .mp4 file name).

Ofc you should test it with a copy of your files (a few would be enough) first!
works great !
it's amazing
thank you sooooo much

Re: can you help me to rename a bunch of srt files?

Posted: 04 Aug 2014 07:39
by giuliastar
highend wrote:

Code: Select all

    $srtFiles = listfolder("<curpath>", "*.srt", 5, "<crlf>");
    $movieFiles = listfolder("<curpath>", "*.mp4", 5, "<crlf>");
    foreach($file, $movieFiles, "<crlf>") {
        $baseName = getpathcomponent($file, "base");
        $ndleading = regexreplace($file, "(^\d+_)(\d+)(-.*)", "$2");
        $match = regexmatches($srtFiles, "$ndleading.*?(?=$)");
        if (gettoken($match, "count", "|") == 1) {
            renameitem($baseName, $match);
        }
    }
Go into the folder that contains the .mp4 and .srt files and execute the above script.
It renames only those files for which it finds a unique match (based on the second leading number of the .mp4 file name).

Ofc you should test it with a copy of your files (a few would be enough) first!
hi
may i ask you a question ?
a script can grab the mp4 name , and rename the srt according to the mp4 name?

thanks

Re: can you help me to rename a bunch of srt files?

Posted: 04 Aug 2014 09:19
by highend
a script can grab the mp4 name , and rename the srt according to the mp4 name?
Em, that's exactly what the script does?

Re: can you help me to rename a bunch of srt files?

Posted: 05 Aug 2014 08:13
by giuliastar
highend wrote:
a script can grab the mp4 name , and rename the srt according to the mp4 name?
Em, that's exactly what the script does?
it works!
but if i rename the mp4 file name , it doesn't work
i would like to ask if a script can grab all the mp4 file name , and use it

Re: can you help me to rename a bunch of srt files?

Posted: 05 Aug 2014 09:38
by highend
but if i rename the mp4 file name , it doesn't work
Be more specific...

- File name before
- File name after renaming
- Belonging .srt file name