Computer Hope

Microsoft => Microsoft DOS => Topic started by: xxentric on October 10, 2009, 07:42:48 AM

Title: .bat to findstr and open file containing string
Post by: xxentric on October 10, 2009, 07:42:48 AM
I am not so good at this at all but im sure trying...

I am trying to get a batch file that will...
1. read a line of text from a text file
2. use that line as the string to search for in all the text files in another directory
3. then when it finds that line of text, i want it to then open that file

.....  is that even possible?

anyway here is the code i have, and im sure the code is gonna be embarrassingly wrong but im hoping for help....

@echo
for /F "tokens=* delims= " %%a in ('findstr /G:%C:%\need\test2.txt %C:%\Need\1\*.txt') do set var=%%a do ( start notepad "%%~a" )



currently im getting .... well nothing happening, batch runs then closes
Title: Re: .bat to findstr and open file containing string
Post by: Salmon Trout on October 10, 2009, 12:19:50 PM
Quote
i want it to then open that file

What if it finds the text in more than one file?
Title: Re: .bat to findstr and open file containing string
Post by: xxentric on October 10, 2009, 12:47:30 PM
I had thought about that, and it shouldn't happen in this case, these numbers are all specific to certain lots.   (but you are right key word here is "shouldn't"

however... if there is way way to display the file(s)  found containing that string in some wort of explorer type window so you can click and open one... that would be even better
Title: Re: .bat to findstr and open file containing string
Post by: billrich on October 11, 2009, 07:09:05 PM
Good Luck