Priti Raut
Priti Raut

Reputation: 13

Renaming multiple files from subdirectories using CMD for EX: 123_abc.pdf file to 123_abc_DOC.pdf

I tried with the below command but is cuts some part of file n replace the _TEST.pdf with it

FOR /R %f IN (*.pdf) DO REN "%f" *_TEST.pdf

EX:
Orgininal file name is TEST_123.pdf

Renamed file name is TEST_TEST.pdf

Expected result is TEST_123_TEST.pdf

Upvotes: 1

Views: 23

Answers (1)

Stephan
Stephan

Reputation: 56180

use modifiers (see for/?):

FOR /R %f IN (*.pdf) DO REN "%~ff" "%~nf_TEST%~xf"

this is command line syntax. To use it in a batch file, double each %:

FOR /R %%f IN (*.pdf) DO REN "%%~ff" "%%~nf_TEST%%~xf"

Upvotes: 1

Related Questions