Reputation: 1
I'm trying to write a batch file to rename multiple files inside multiple folders and can't quite figure it out.
The folder names all follow the same structure: "foo.bar_baz" and all the files inside the folder are 2 character codes (AA, AB, BC) and all share the same extension. foo and baz are constant throughout all the folders and bar changes every time. I want to rename all the files as bar_.
I don't have a lot of experience with batch files so I'm probably missing something obvious but I can"t figure it out.
Upvotes: 0
Views: 408
Reputation: 73526
@echo off
for /d /r "d:\some\dir\" %%d in (*) do (
for /f "delims=._ tokens=2" %%b in ("%%~nxd") do (
for %%f in ("%%~d\??.*") do ren "%%~f" "%%b_%%~nxf"
)
)
pause
Upvotes: 1