Skip to content

Instantly share code, notes, and snippets.

@brovish
Created February 7, 2024 10:46
Show Gist options
  • Select an option

  • Save brovish/c43da704c63983034c4f8baf66721ac4 to your computer and use it in GitHub Desktop.

Select an option

Save brovish/c43da704c63983034c4f8baf66721ac4 to your computer and use it in GitHub Desktop.
search_info_file_v3.cmd c:\temp file.ini string
@echo off
setlocal EnableDelayedExpansion
if "%~3"=="" (
echo Incorrect usage. The correct usage is: %~nx0 "Search Directory" "Filename Pattern" "Search String"
exit /b
)
set "SEARCH_DIR=%~1"
set "FILENAME_PATTERN=%~2"
set "SEARCH_STRING=%~3"
set "TEMP_FILE=%TEMP%\filelist.txt"
dir /S /B "%SEARCH_DIR%\%FILENAME_PATTERN%" > "%TEMP_FILE%"
for /F "delims=" %%F in (%TEMP_FILE%) do (
findstr /M /I /C:"%SEARCH_STRING%" "%%F" >nul
if !errorlevel! equ 0 (
echo Contains string: "%%F"
) else (
echo Does not contain string: "%%F"
)
)
del "%TEMP_FILE%"
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment