Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: .bat to findstr and open file containing string  (Read 3453 times)

0 Members and 1 Guest are viewing this topic.

xxentric

    Topic Starter


    Starter

    .bat to findstr and open file containing string
    « 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

    Salmon Trout

    • Guest
    Re: .bat to findstr and open file containing string
    « Reply #1 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?

    xxentric

      Topic Starter


      Starter

      Re: .bat to findstr and open file containing string
      « Reply #2 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

      billrich

      • Guest
      Re: .bat to findstr and open file containing string
      « Reply #3 on: October 11, 2009, 07:09:05 PM »
      Good Luck
      « Last Edit: October 12, 2009, 11:03:18 AM by billrich »