Steffen Kristensen
Steffen Kristensen

Reputation: 11

Batch files with findstr and rename

I am quite new at this, but anyway I try. How do I code a batch file to find a file containing a specific word an then rename that file? I use findstr, and it find the file, but how do i catch the ouput from this, and use the output to rename the file or those files?

i hope that someone Can help me. Thank you Steffen

Upvotes: 0

Views: 1202

Answers (1)

Magoo
Magoo

Reputation: 80043

Primitively,

@ECHO OFF
SETLOCAL
SET "sourcedir=u:\sourcedir"
FOR /f "delims=" %%a IN ('findstr /m /L /c:"find me" "%sourcedir%\*.*"') DO (
 ECHO(REN "%%a" "destinationname"
)

GOTO :EOF

You would need to change the setting of sourcedir to suit your circumstances.

The game however is in what you haven't told us - how you want to rename the file, since you can only have one file with any particular name in a directory.

Upvotes: 1

Related Questions