I am currently trying to get a batch file to work correctly, and having mild success. I'm still waiting for approval at work to have a VS ide installed on my work computer, but until then I need to go ahead and work on this batch file which may suit my needs, and even just incorporate it into my actual program when the time comes.
So heres what I'm trying to do. I want to make a batch file that will search through the current folder, and all subfolders for a specific word or phrase in all txt files that are found. The user chooses the search string, and then I need a way to be able to return the path to that txt file that contained the search string. This is what I have so far.
Code: Select all
@echo off
:SEARCH
set /p choice=Enter the search word or phrase to find the QF:
FINDSTR /s /i /L /c:"%choice%" *.txt > temp.txt
set /p exit= Do you want to try to search again: 1 for yes, 2 for no.
IF %exit%==1 GOTO SEARCH
IF %exit%==2 exit
The only problem with this is that it returns the path AND the search phrase that was found in the text file. if multiple txt files were found, it puts them each on separate lines, which is great. However I only really need the path. (so that later on i can give the user a choice to launch one of the text files that were found.)
Here is an example of the temp.txt output. This is returned by searching for the word "loyalty"
QF Folder Structure\Version 8.02\Service Packs\QF17.txt:Loyalty Interface Issues
QF Folder Structure\Version 8.04\Service Packs\QF3.txt:Loyalty Adjustment Issue
So, all I really want to do, is get rid of the " : " and anything to the right of it. Just so I have the paths to the text files, 1 path per line. I've had issues trying to use for /f and I guess I don't understand the tokens and delims parameters.
Any help would be appreciated!
Thanks.