Page 1 of 1
help!
Posted: 13 Oct 2011 01:45
by glob5
I AM NEW TO BAT SCRIPT WORLD. MY SCRIPT DOES NOT WANT TO WORK. MY BAT SCRIPT HAS TO start from a path and RECURSIVELY SEARCH ALL THE FILES OF TYPE .TXT THAT HAS THE WORD "MYWORD!" AND WRITE THEIR NAMES TO A LOG FILE.
Re: help!
Posted: 13 Oct 2011 08:53
by dbenham
Code: Select all
@echo off
set "log=output.log"
set "search=MYWORD!"
set "startPath=."
::Dot implies current directory
(for /f "delims=" %%F in ('dir /s /b "%startPath%\*.txt"') do findstr /c:"%search%" "%%F" >nul && echo %%F)>"%log%"
Dave Benham
Re: help!
Posted: 15 Oct 2011 11:38
by glob5
How about if I look for a phrase which has two words like this: set "search=MYWORD1 MYWORD2" . Notice the space.
Re: help!
Posted: 15 Oct 2011 14:30
by nitt
glob5 wrote:I AM NEW TO BAT SCRIPT WORLD. MY SCRIPT DOES NOT WANT TO WORK. MY BAT SCRIPT HAS TO start from a path and RECURSIVELY SEARCH ALL THE FILES OF TYPE .TXT THAT HAS THE WORD "MYWORD!" AND WRITE THEIR NAMES TO A LOG FILE.
This seems like trollish spam, but I will take it seriously.
Code: Select all
@echo off
dir /b /a /s | find "MYWORD!" > ~tmp.txt
type ~tmp.txt | find ".txt" > log.txt
type ~tmp.txt | find ".TXT" >> log.txt
del ~tmp.txt
That will search all directories and list files containing "MYWORD!" and will only list them if the extensions are ".txt" or ".TXT".
Re: help!
Posted: 15 Oct 2011 18:37
by glob5
can we search for phrase like "MYWORD1 MYWORD2"?.
Re: help!
Posted: 16 Oct 2011 09:13
by aGerman
What about
Code: Select all
>"my.log" findstr /msc:"MYWORD1 MYWORD2" "C:\wherever\*.txt"
Note that it's searching in a case-sensitive manner (that could be a problem because it seems your caps lock key is out of order). Otherwise you have to include the /i option (
/imsc:).
Regards
aGerman