0
  • Fullcast 01 [3m].jpg
  • Fullcast 01 [5m].jpg
  • KingPin - 02 [3m].jpg
  • KingPin - 02 [5m].jpg
  • ThemaCast - 8745 [3m].png
  • ThemaCast - 8745 [5m].png

I have multiple groups of files [group - Fullcast,KingPin,etc...] which follow the above pattern .I want to replace the strings [3m] with BZC and [5m] with HZC in all those files and also replace the strings "Fullcast" with "Fllcst" ; "KingPin" with "KngPn" ; "Themecast" with "ThemaCst" and so on......... using a single bat file.

I got answer but only for a single string - How to rename file by replacing substring using batch in Windows

I can create multiple bat files but How to rename those using a single bat file ? Note : the files are in "D:\Images\" and i want to launch the bat file from Desktop [C:\Documents and Settings\XXX\Desktop]

1 Answer 1

0

You didn't say how your script was going to get the list of files on which to operate. This example assumes that you're looking at all the files in the current directory.

@ECHO OFF
SETLOCAL 

FOR %%i IN (*.jpg) DO CALL :CUSTOM_RENAME "%%~i"
FOR %%i IN (*.png) DO CALL :CUSTOM_RENAME "%%~i"

EXIT /B

:CUSTOM_RENAME
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "delims=*" %%f IN ("%~1") DO (
    SET "SOURCE=%%~f"
    SET "NEWNAME=%%~nxf"
)
SET "NEWNAME=!NEWNAME:[3m]=BZC!"
SET "NEWNAME=!NEWNAME:[5m]=HZC!"
REM Other substitutions would go here, assuming they don't overlap.

@ECHO "!SOURCE!" --^> "!NEWNAME!"
rename "!SOURCE!" "!NEWNAME!"
ENDLOCAL
EXIT /B
Sign up to request clarification or add additional context in comments.

2 Comments

The files are in Directory Ex. D:/Images/ and i want to place the bat file on Windows Desktop Screen ,
i have refined the question more...need your help mojo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.