私は、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