FIND "[ERR" "text.csv" sets ERRORLEVEL to 0 if at least one [ERR
is found, and 1 if no [ERR
is found. You need a way to invert the logic.
If all you want to do is immediately return 0 if no [ERR
found, or 1
if at least one [ERR
found, then I would use the following:
find "[ERR" "test.csv" >nul && exit /b 1 || exit /b 0
If you want to capture the result in a variable to be returned later, then:
find "[ERR" "test.csv" >nul && set "err=1" || set "err=0"
or
find "[ERR" "test.csv" >nul
set /a "err=!%errorlevel%"
When you are ready to return the result
exit /b %err%
Below is my original answer that was accepted, yet was embarrassingly wrong :-(
Thanks Corey for pointing out the logic error. As he says in his comment, the faulty code below will only report an error if all of the lines have the [ERR
text.
FIND will set the ERRORLEVEL to 0 if found, 1 if not found. To reverse
the logic, simply use the /V option.
find /v "[ERR" "test.csv" >nul
If you have a variable set that indicates the errorlevel, then you can
use EXIT /B to set the ERRORLEVEL
set err=1
exit /b %err%