Q:

Batch script to search a string in multiple xml files

I wrote a batch script to search a string "Error" in multiple XML files in a folder. 
I'm using a for loop to iterate through all the files and using a find command to search the specific string in those files.
But, I see that the searching of string in a particular file happens only after one complete iteration instead of at the line where the find command is written. It doesn't give correct output.
I wrote the following script (Windows):
cd C:\Logs\
setlocal EnableDelayedExpansion 
for /r . %%g in (*.xml) do ( set xml_file_name=%%~nxg 

 find /I "Error"  "C:\Logs\!xml_file_name!"
 if %errorlevel%==0 ( 
   echo Error found at C:\Logs\!xml_file_name!
 ) else (
   echo No Error found.
   exit )
 )

There are about 10-15 xml files and if there is a string "Error" in a xml file it should output "error found" else "no error found" for each file.
Please help me with the correct code.

A:

You have an exit in „else“ case? So it quits after first „no error found“
EDIT: try this:
echo off
cd C:\Logs\
setlocal EnableDelayedExpansion 

setlocal EnableDelayedExpansion 
for /r . %%g in (*.xml) do ( set xml_file_name=%%~nxg 

    find /I "Error"  "C:\Logs\!xml_file_name!" > nul & if errorlevel 1 ( 
        echo No Error found.
    ) else (
        echo Error found at C:\Logs\!xml_file_name!
    )
)

