I would use FINDSTR with DIR /B and FOR /F
The following will process names with any number of extra extensions like name.txt.ext
and name.txt.ext.ext
, etc. This includes a name like name.txt.txt
for /f "delims= eol=:" %%F in (
'dir /b /a-d *.txt.*^|findstr /i "\.txt\."'
) do call :renum "%%F"
This variation will only process names with a single extra extension like name.txt.ext
(including name.txt.txt
)
for /f "delims= eol=:" %%F in (
'dir /b /a-d *.txt.*^|findstr /i "\.txt\.[^.]*$"'
) do call :renum "%%F"
You might also check into my JREN.BAT regular expression file renaming utility. It can probably filter and rename all your files in one step, without any need for a custom batch script.
For example, the following will only rename files looking like "name.txt.ext", and transform them into "name_ext.txt"
jren "(\.txt)\.([^.]+)$" "_$2$1" /i