A simply though clumsy method is to rename the files twice – first remove .srt
, then change .en
to .srt
(given that there are no other files *.en
):
ren "*.en.srt" "*." & ren "*.en" "*.srt"
A more elegant solution is the one provided by user Mofi in his comment:
@for /F "eol=| delims=" %I in ('dir "*.en.srt" /B /A:-D 2^> nul') do @for %J in ("%~nI") do @ren "%~I" "%~nJ%~xI"
In a batch-file this code would look similar to this (note the necessarily doubled %
-signs):
@echo off
rem // Loop through all matching files:
for /F "eol=| delims=" %%I in ('dir "*.en.srt" /B /A:-D 2^> nul') do (
rem /* There are `~`-modifiers for `for` meta-variables that allow to split file names:
rem `~n` returns the base name, so the (last) extension becomes removed;
rem `~x` returns the extension (including the leading `.`);
rem therefore, `%%~nI` is the original file name with `.srt` removed, hence
rem ending with `.en`, and `%%~xI` is the original extension `.srt`;
rem another loop is used to also split off `.en` from `%%~nI`: */
for %%J in ("%%~nI") do (
rem /* Now `%%~J` returned the same as `%%~nI`, but `%%~nJ` removes `.en`;
rem so finally, rename the file to `%%~nJ` plus the original extension `.srt`: */
ren "%%~I" "%%~nJ%%~xI"
)
)
Following the thorough thread How does the Windows RENAME command interpret wildcards? on Super User, I found out that there is a way using a single ren
command:
ren "*.en.srt" "?????????????????????????????????????????.srt"
However, you need to make sure to have enough ?
, namely as many as there are characters in longest matching file name without .en.srt
; otherwise, file names become truncated. You can avoid truncation by replacing the same sequence of ?
instead of *
, so longer file names are not renamed at all:
ren "?????????????????????????????????????????.en.srt" "?????????????????????????????????????????.srt"
Anyway, this only works when the original file names do not contain any more .
besides the two in .en.srt
; otherwise, everything behind the first .
becomes removed and (finally replaced by srt
).