0

这是基于我最后一个问题的脚本:,目录映射不起作用(BATCH)

(对于整个脚本,请单击链接。但是,如果“ directory mapout is not working ”中的以下代码片段对您没有真正意义,您只能单击该链接)

<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>

我希望“for /f”命令从一个搜索词中输出许多搜索结果。 代码格式不正确?请留言/评论这个问题。

4

1 回答 1

1

如果您只想显示匹配的行,则完全放弃 FOR /F

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

如果您需要匹配行的“数组”,则:

:: 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!
于 2013-09-05T13:51:29.467 回答