Find Text and Rename File

I have a batch file which searches for text within files and renames the files accordingly. The problem is that it doesn't look for exact matches:

@echo off

for /f "delims=" %%a in ('findstr /m "General Ledger Summary Report" c:\Temp\*.prt') do ren "%%a" OFMREP052.prt

If the exact match isn't in the folder then any file with "General Ledger" in it will be renamed.

How can I force the batch file to search for exact matches?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RediersEUS Technology LeadCommented:
/l should do the trick...
See below

@echo off

for /f "delims=" %%a in ('findstr /m /l "General Ledger Summary Report" c:\Temp\*.prt') do ren "%%a" OFMREP052.prt

Have u tried using /X parameter ?
Bill PrewIT / Software Engineering ConsultantCommented:
You will want the /C flag, as in:

@echo off
for /f "delims=" %%a in ('findstr /m /c:"General Ledger Summary Report" c:\Temp\*.prt') do ren "%%a" OFMREP052.prt

Open in new window

If you want to ignore case add the /i option as well.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Steve KnightIT ConsultancyCommented:
you could just use FIND instead of findstr too:

FIND /I "General ledger......" c:\temp\*.prt


presumably as you are renaming to one filename there is no danger 2xsource or an existing destination file exists already?
jonlakeAuthor Commented:
Thank you to everyone who contributed. Billprew's solution matched precisely what I was after.
Bill PrewIT / Software Engineering ConsultantCommented:
Glad that helped, thanks.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.