In short, the list of files retrieved by the for
command is dynamic. If initially there is more than one file matching the set, then the list will be rereaded (more info here) and if the first processed file is renamed to anything that also matches the set in for
command, it will be reprocessed.
One solution is to first retrieve the full list and then process it. It can be done with for /f
and dir
commands
for /f "delims=" %%i in ('dir /b /a-d "*.%x%"') do ( ....
for /f
will always retrieve all the information to process before starting to process it. So, the dir command is executed once and then its output processed.
Other solution (as indicated in comments by OP) is to ensure the indicated set of files in for
command will not match the new renamed files.
(??.%x%)
to void it in my case. – Chance Door