About
Pricing
Community
Teams
Start Free Trial
Log in
jonlake
asked on
10/5/2011
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?
Microsoft DOS
6
1
Last Comment
Bill Prew
8/22/2022 - Mon
Rediers
10/5/2011
/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
pritamdutt
10/5/2011
Have u tried using /X parameter ?
ASKER CERTIFIED SOLUTION
Bill Prew
10/5/2011
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Steve Knight
10/5/2011
you could just use FIND instead of findstr too:
FIND /I "General ledger......" c:\temp\*.prt
etc.
presumably as you are renaming to one filename there is no danger 2xsource or an existing destination file exists already?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
jonlake
10/5/2011
ASKER
Thank you to everyone who contributed. Billprew's solution matched precisely what I was after.
Bill Prew
10/5/2011
Glad that helped, thanks.
~bp
See below
@echo off
for /f "delims=" %%a in ('findstr /m /l "General Ledger Summary Report" c:\Temp\*.prt') do ren "%%a" OFMREP052.prt