Batch Script to Bulk Rename Files - Strip off Parenthesis and all Characters between

2

I wish to rename a group of files in a particular folder in such a way that everything between and including the parenthesis is erased.

For example a file with the name of:

"78 Tax Tips for Canadians for Dummies (ISBN - 0470676582)"

I wish to rename it to:

"78 Tax Tips for Canadians for Dummies"

I need to do this for all the files file in a particular folder for any and all files that follow this same pattern for it's file name characters:

Dummies (ISBN - .........)

I tried following and using the batch script logic on this post but I could not get that to work the number after the ISBN - ########## part keeps changing with the way I did that incorrectly.

Saransh Reu

Posted 2016-02-01T14:06:40.083

Reputation: 23

forgive me but i am not able to figure it out. i request you to give me a command line. – Saransh Reu – 2016-02-01T14:17:23.153

2The link above describes what you want to do with a little bit of tinkering around. That's exactly what you need, a batch script to rename files. – Matt King – 2016-02-01T14:20:35.457

i am someone who is a stranger to coding. i hope you can understand my position. therefore i need a ready made command line. – Saransh Reu – 2016-02-01T14:23:51.913

unlike in the link you mentioned, the number after ISBN - ' ' keeps changing, so i am not able to do it. – Saransh Reu – 2016-02-01T14:43:17.863

Answers

1

Batch file rename, strip off parenthesis and all characters between, but keep extension

Save all the logic from the below example to a text file and name it something.cmd and then simply execute it. . .

Script Notes

  • Where SET RenDir=C:\Path is C:\Path, you'll need to put the full path where these files you wish to rename exist.

  • The assumption with this script logic is there will ONLY be files in the RenDir with parenthesis () that will need to be stripped with the (ISBN - .........) type pattern and no other parts of any of those file names will contain any parenthesis ().

Example Batch Script Logic

@ECHO ON

SET RenDir=C:\Path

FOR /F "DELIMS=() TOKENS=1,3" %%F IN ('DIR /B /A-D "%RenDir%\*.*"') DO (
    CALL :RenameFiles "%%~F" "%%~G"
)
GOTO EOF

:RenameFiles
SET fname=%~1
SET Ext=%~2
REN "%RenDir%\%fname%*%ext%" "%fname%%ext%"
GOTO EOF

Pimp Juice IT

Posted 2016-02-01T14:06:40.083

Reputation: 29 425

should i copy and paste the entire code in cmd window ? – Saransh Reu – 2016-02-01T15:06:29.963