Here is the code:
for /r %%a in (*.jpg, *.png, *.bmp, *.exe) do (
for /d %%d in (%CD%) do (
set newname=%%~nd%~x1
ren "%%~a" "!newname!%%~Xa"
echo media file in %%~fa renamed to "!newname!%%~Xa"
)
)
The main problem is that the files in the subfolders end up with filename as the parent directory name i run the bat file from.
Example of what happens:
C:\parent\name.jpg renamed to C:\parent\parent.jpg
C:\parent\child\name.jpg renamed to C:\parent\child\parent.jpg
C:\parent\child1\child2\name.jpg renamed to C:\parent\child1\child2\parent.jpg
I need:
C:\parent\1.jpg rename to C:\parent\parent.jpg
C:\parent\child\1.jpg rename to C:\parent\child\child.jpg
C:\parent\child1\child2\name.jpg renamed to C:\parent\child1\child2\child2.jpg
Any help?