It is hard to see where your message is pseudo-code and where the valid code is.
The first sample contains only REM expressions, so it is not surprising that it does nothing.
Your second and third examples are virtually identical - the only difference is the target line. Unsurprisingly, the skip variable is not set to Yes , because the correct syntax is
if %errorlevel% equ 0 set skip=Yes
The syntax you posted will be REPORT that skip not defined - it ignores Yes
HOWEVER this syntax is used only by OUTSIDE for a "block statement" , that is, instructions with multiple instructions (enclosed in parentheses) or cascading & using ampersands. The package first PARSES complete statement - from FOR or if to the corresponding closing parenthesis and THEN executes it. As part of the PARSING phase PARSING any %var% β including %errorlevel% is replaced with its value, because it stands at a time when the entire parsed statement parsed not change, since it works with FOR .
To use a value when changing it, you need to use
if errorlevel 1 (do_something) else (do_something_else)
where do_something and do_something_else) themselves can be compound statements.
OR
if defined variable (do_something) else (do_something_else)
where the variable is either defined or not
OR
setlocal enabledelayedexpansion .... if !errorlevel! equ x (do_something) else (do_something_else)
OR
if !var! neq something (do_something) else (do_something_else)
But it is entirely possible that
FOR /R "%somepath%" %%G in (*.avi) DO ( echo(%%G|findstr /i "sample trailer" >nul if errorlevel 1 echo %%G )
will provide you with the appropriate skeleton.
Cut the file name through FINDSTR and look for the " FINDSTR " or "trailer" /i case insensitive. Findstr sets errorlevel 0 if one target string is found, otherwise, and if errorlevel x syntax works with the dynamic value of errorlevel inside the loop.