My current batch searches each line from STRINGS.txt (as string) in any .txt files in C:\FOLDER\ (subfolders included). It says to me if each string exists and in which file. The output file is IF_STRING_EXISTS.txt.
It works, but now i need to optimize and customize it, because in some cases there are thousands of txt files in FOLDER\ and i have hundreds of strings.
My wishes :
1) I don't want to know where each string exists, but if they exist or not. So, if it finds a string one time, it can immediately search next string (instead of searching in remaining files).
2) I prefer to search in some subdirectories only, because some of them are useless. Say i want to search in C:\FOLDER\a\ and in C:\FOLDER\b\ instead of C:\FOLDER\. How should I write it? I tried to add a | or a ; as separator, but to no avail.
My current batch :
Code: Select all
@echo off
setlocal enableextensions disabledelayedexpansion
set "manifest_folder=C:\FOLDER\*.txt"
set "file_list=STRINGS.txt"
(for /f "usebackq delims=" %%a in ("%file_list%") do (
set "found="
for /f "delims=" %%b in ('findstr /l /m /s /c:"%%a" "%manifest_folder%"') do (
echo %%a is found in %%~nxb
set "found=1"
)
if not defined found (
echo %%a is not found
)
)) > "IF_STRING_EXISTS.txt"
Thanks in advance
EDIT:
Best answer from foxidrive. New batch :
Code: Select all
@echo off
set manifest_folder="C:\FOLDER\a";"C:\FOLDER\b"
set "file_list=STRINGS.txt"
(
for /f "usebackq delims=" %%a in ("%file_list%") do (
findstr /l /m /s /c:"%%a" /d:%manifest_folder% *.txt >nul && (
echo %%a is found
) || (echo %%a is not found)
)) > "IF_STRING_EXISTS.txt"