Search code examples
batch-filefindstr

Use Path Dir from findstr command


Trying to use the directory outputed by this line in my batch code.

findstr /M search_text "C:\Users\user\Desktop\*"

This output's a file directory.

"C:\Users\whatever\blabla"

I know I can just add >> and print it to a text file but I'd rather not go that route as I'm not sure how to pull the dir back into the command line in the first place. Is there somehow I can do like a Set=%k command to a variable for later use. Sorry I'm still very new to this. Thanks for any help!


Solution

  • You can do this

    for /f %%i in ('findstr /m "search_text" "C:\Users\user\Desktop\*"') do set file=%%i
    

    Then you have the output in the %file% variable.

    Hope this helps.