import re s=r"""D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E01.WEBRip.Netflix.en[cc].srt D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E02.WEBRip.Netflix.en[cc].srt D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E03.WEBRip.Netflix.en[cc].srt D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E04.WEBRip.Netflix.en[cc].srt D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E05.WEBRip.Netflix.en[cc].srt D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E06.WEBRip.Netflix.en[cc].srt D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E01.WEBRip.Netflix.ja.srt D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E02.WEBRip.Netflix.ja.srt D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E03.WEBRip.Netflix.ja.srt D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E04.WEBRip.Netflix.ja.srt D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E05.WEBRip.Netflix.ja.srt D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E06.WEBRip.Netflix.ja.srt D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E01.WEBRip.Netflix.ja-forced.srt D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E02.WEBRip.Netflix.ja-forced.srt D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E03.WEBRip.Netflix.ja-forced.srt D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E04.WEBRip.Netflix.ja-forced.srt D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E05.WEBRip.Netflix.ja-forced.srt D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E06.WEBRip.Netflix.ja-forced.srt D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E01.WEBRip.Netflix.zh-Hant.srt D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E02.WEBRip.Netflix.zh-Hant.srt D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E03.WEBRip.Netflix.zh-Hant.srt D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E04.WEBRip.Netflix.zh-Hant.srt D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E05.WEBRip.Netflix.zh-Hant.srt D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E06.WEBRip.Netflix.zh-Hant.srt""" s2=r"""EP01 浪人.MP4 EP02 老方法.MP4 EP03 彌天大罪.MP4 EP04 漫漫長路.MP4 EP05 痛楚與鮮血.MP4 EP06 平衡.MP4""" a=sorted([_ for _ in list(filter(None, s.split('\n')))]) b=sorted([_ for _ in list(filter(None, s2.split('\n')))], key=lambda _:re.match(r"(?P<p>EP?\d+\s?)?(?P<n>.*?)\..*", _).group('p')) for i, _ in enumerate(a): print('ren "{}" "{}{}"\n'.format(_,b[i%len(b)],re.match(r".*?(?P<f>(?:.(?!\.))+$)",_).group('f')))
Standard input is empty
ren "D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E01.WEBRip.Netflix.en[cc].srt" "EP01 浪人.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E02.WEBRip.Netflix.en[cc].srt" "EP02 老方法.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E03.WEBRip.Netflix.en[cc].srt" "EP03 彌天大罪.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E04.WEBRip.Netflix.en[cc].srt" "EP04 漫漫長路.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E05.WEBRip.Netflix.en[cc].srt" "EP05 痛楚與鮮血.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\en[cc]\武士彌助.S01E06.WEBRip.Netflix.en[cc].srt" "EP06 平衡.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E01.WEBRip.Netflix.ja-forced.srt" "EP01 浪人.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E02.WEBRip.Netflix.ja-forced.srt" "EP02 老方法.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E03.WEBRip.Netflix.ja-forced.srt" "EP03 彌天大罪.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E04.WEBRip.Netflix.ja-forced.srt" "EP04 漫漫長路.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E05.WEBRip.Netflix.ja-forced.srt" "EP05 痛楚與鮮血.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja-forced\武士彌助.S01E06.WEBRip.Netflix.ja-forced.srt" "EP06 平衡.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E01.WEBRip.Netflix.ja.srt" "EP01 浪人.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E02.WEBRip.Netflix.ja.srt" "EP02 老方法.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E03.WEBRip.Netflix.ja.srt" "EP03 彌天大罪.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E04.WEBRip.Netflix.ja.srt" "EP04 漫漫長路.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E05.WEBRip.Netflix.ja.srt" "EP05 痛楚與鮮血.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\ja\武士彌助.S01E06.WEBRip.Netflix.ja.srt" "EP06 平衡.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E01.WEBRip.Netflix.zh-Hant.srt" "EP01 浪人.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E02.WEBRip.Netflix.zh-Hant.srt" "EP02 老方法.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E03.WEBRip.Netflix.zh-Hant.srt" "EP03 彌天大罪.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E04.WEBRip.Netflix.zh-Hant.srt" "EP04 漫漫長路.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E05.WEBRip.Netflix.zh-Hant.srt" "EP05 痛楚與鮮血.MP4.srt" ren "D:\Video\武士彌助\subtitles\S01\zh-Hant\武士彌助.S01E06.WEBRip.Netflix.zh-Hant.srt" "EP06 平衡.MP4.srt"