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

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
giuliastar
Posts: 365
Joined: 14 Sep 2013 07:22

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

Post 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

highend
Posts: 14952
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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?
One of my scripts helped you out? Please donate via Paypal

giuliastar
Posts: 365
Joined: 14 Sep 2013 07:22

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

Post 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

highend
Posts: 14952
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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!
One of my scripts helped you out? Please donate via Paypal

giuliastar
Posts: 365
Joined: 14 Sep 2013 07:22

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

Post 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

giuliastar
Posts: 365
Joined: 14 Sep 2013 07:22

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

Post 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

highend
Posts: 14952
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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?
One of my scripts helped you out? Please donate via Paypal

giuliastar
Posts: 365
Joined: 14 Sep 2013 07:22

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

Post 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

highend
Posts: 14952
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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
One of my scripts helped you out? Please donate via Paypal

Post Reply