我刚刚开始接触 MS Batch 文件。我创建了一个小批量,它使用 findstr /m 在输入的目录中搜索包含某个字符串的文件。它返回一个包含字符串的文件,但只返回它找到的第一个。我已经搜索了 findstr /? 和在线命令参考,以及这个站点。我找不到让 findstr 返回所有带有字符串实例的文件的方法。我错过了什么?
@echo off
setlocal
ECHO This Program Searches for words inside files!
:Search
set /P userin=Enter Search Term:
set /p userpath=Enter File Path:
FOR /F %%i in ('findstr /M /S /I /P /C:%userin% %userpath%\*.*') do SET finame=%%i
if "%finame%" == "" (set finame=No matching files found)
echo %finame%
set finame=
endlocal
:searchagain
set /p userin=Do you want to search for another file? (Y/N):
if /I "%userin%" == "Y" GOTO Search
if /I "%userin%" == "N" GOTO :EOF ELSE (
GOTO wronginput
)
Pause
:wronginput
ECHO You have selected a choice that is unavailable
GOTO searchagain