This will echo the ren commands to the screen.
Remove the echo
keyword to make it actually perform the renames.
@echo off
for /r %%a in (*.jpg *.png *.bmp *.exe) do for %%b in ("%%~dpa\.") do echo ren "%%~a" "%%~nxb%%~xa"
pause
The first %%a FOR command returns each filespec recursively and the format of each file is:
c:\path\to\folder\filename.ext
The second %%b FOR is given the c:\path\to\folder
portion and \.
is added to the end making it c:\path\to\folder\.
which resolves to the current directory of to
and making it interpret folder
as the filename.
So the %%~nxb
returns the filename and extension of %%b which is folder
in this case, and that is used in the rename command. %%~xa
returns the .extension of the %%a string.
I hope that's fairly clear, along with examining the code.
The last page of the FOR /?
help describes the metavariables.