Rename images to folder name batch file

Ray Padilla
Ray Padilla used Ask the Experts™
on
This is the tree in the folders:
\WaterMark04292015\4B-MiniMatic-2-1mm-adj-AR21040-HTML\Images\4B-MiniMatic-2-1mm-adj-AR21040-HTML\Lv1

In this tree under the LV1 folder  there are images named: img01.jpg/img02.jpg/img03.jpg etc. upto img20.jpg

I want to rename the images to: 4B-MiniMatic-2-1mm-adj-AR21040_01.jpg uptil _20.jpg

I attached a listing of the folders within the main folder. Can a batch file be used to do this or is there a third party app I can use?
folders.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer

Commented:
Can a batch file be used to do this or is there a third party app I can use?

Yes and yes.
Ray PadillaIT  Director

Author

Commented:
thanks I need a batch file that will do this for me or a recommendation of an application that will do this.
End-user support
Commented:
- Make a .bat file of this code.
- Code makes a .log in your TEMP folder
- Be sure to do on a test folder first!
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set fnlog=%temp%\%~n0.log
set ParentDir=C:\Users\Raymond\Desktop\Temp Files\WaterMark04292015

echo %date% %time% BEGIN %0 >>"%fnlog%"
pushd %ParentDir%
for /d %%a in (*) do (
  echo %%a
  pushd "%%a\images\%%a\lv1"
  echo %cd% >>"%fnlog%"
  for %%A in (*.jpg) do (
    set fnsfx=%%A
    set fn=%%a_!fnsfx:~3!
    echo ren "%%A" "!fn!" >>"%fnlog%"
    ren "%%A" "!fn!"
    set fnsfx=
    set fn=
  )
  popd
)
popd
echo %date% %time% END %0 >>"%fnlog%"

Open in new window

Ray PadillaIT  Director

Author

Commented:
thanks worked!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial