1

To put simply I am a temp IT for (Blank) motor company. I am trying to build a batch file that will search Progresslog.txt for a string. this string will be a user name like awilson. Thing is there is 1 progresslog.txt for each computer I have backed up under the folder names HMC(insert s/n) I need to search each progresslog for the string but can't figure out what I'm doing. This is what I have so far.

for /d /r ".\" %%a in (*) do if /i "%%~nxa"=="progresslog.txt" set "folderpath=%%a" & echo "%folderpath%"
for /f %%f in ('dir /b %folderpath%') do echo %%f & findstr /m "%Input%" progresslog.txt
if %errorlevel%==0 (
  echo Found String!
) else goto A
dbenham
  • 127,446
  • 28
  • 251
  • 390
kyydrek
  • 11
  • 1

1 Answers1

1

It is a lot easier

findstr /s /l /m /c:"awilson" progresslog.txt

Just search in subdirectories (/s) the literal indicated (/l /c:"...") in files named progresslog.txt and output only the name of files found (/m)

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • 1
    The `/C:"string"` option defaults to a literal serach, so the `/L` option is redunant. – dbenham Jun 25 '15 at 20:29
  • The solution should work well for this case. But you have to be careful with the `/S` option. FINDSTR has a serious bug that can lead to skipped files under certain circumstances. See the section titled **BUG - Short 8.3 filenames can break the /D and /S options** at http://stackoverflow.com/a/8844873/1012053. – dbenham Jun 25 '15 at 20:36
  • @dbenham, thank you. I have lost the count of how many times I have readed your answer on `findstr`. Yes I'm aware of the redundant switch (`findstr` has so many quirks that I prefer to precisely indicate what I'm doing) and of course all the bugs you documented. I think that in this case, with a fixed long file name, without wildcards, it should work. – MC ND Jun 25 '15 at 20:58
  • Agreed - it should work here. I just wanted the OP to be aware that there are unexpected limitations to the `/S` option that could arise in seemingly similar use cases. – dbenham Jun 25 '15 at 21:12