0

This is based on my last question's script:, Directory mapout is not working (BATCH)

(For the whole script, click the link. However, you may only click the link if the following snip of code from "directory mapout is not working" does not really make sense to you)

<code>
cd temporary
set odir=%dir%
set /p cdir="DIRECTORY: " 
set domap=%cdir%
title SONOROUS FILE SEARCHER: Mapping out...
echo PLEASE WAIT, MAPPING OUT DIRECTORY.
dir %domap% /a-d /b /s > "tempres.rsm"
echo Directory Mapout done
echo -----------------------------
echo       DIRECTORY MAPOUT
set dirmapout=<tempres.rsm
echo %dirmapout%
echo -----------------------------
title SONOROUS FILE SEARCHER: Mapout done.
set /p "searchinput=Search Term: "
title SONOROUS FILE SEARCHER (Copyright 2013 by Sonorous)
for /f "delims=" %%a in ('findstr /i /L /c:"%searchinput%" "tempres.rsm" ') do set "found=%%a"
set proin=%found%
echo "%found%"
cd temporary
del "tempres.rsm"
</code>

I want the "for /f" command to output MANY search results from one search term. Is the code not correctly formatted? Please message / comment on this question.

Community
  • 1
  • 1
Epic_Tonic
  • 96
  • 1
  • 9

1 Answers1

1

If you simply want to display the matching lines, then ditch the FOR /F altogether

title SONOROUS FILE SEARCHER (Copyright 2013 by Sonorous)
findstr /i /L /c:"%searchinput%" "tempres.rsm"
cd temporary
del "tempres.rsm"

If you need an "array" of matching lines, then:

:: Define the array of matching lines
set "foundCount=0"
for /f delims^=^ eol^= %%a in ('findstr /i /L /c:"%searchinput%" "tempres.rsm" ') do (
  set /a "foundCount+=1"
  setlocal enableDelayedExpansion
  for %%N in (!foundCount!) do (
    endlocal
    set "found%%N=%%a"
  )
)

:: Display the array values
setlocal enableDelayedExpansion
for /l %%N in (1 1 %foundCount%) do echo match %%N = !found%%N!
dbenham
  • 127,446
  • 28
  • 251
  • 390