Вот пример.
Запускаю ниженаписанный батник для проверки и открывается окно paint, хотя должно появиться сообщение New file not created!
Код:

@echo Off
cls
set "Mask=log*."
set "BoxIn=C:\11\"
set "Prg1=start /wait " " "C:\Program Files\Windows NT\Accessories\wordpad.exe""
set "Prg="C:\Windows\System32\mspaint.exe"
set "OldFile="
for /F "usebackq delims=" %%f in (`2^>nul dir "%BoxIn%\%Mask%" /b /a:-d /o:-d /t:c`) do set "OldFile=%%f"
%Prg1%
for /F "usebackq delims=" %%f in (`2^>nul dir "%BoxIn%\%Mask%" /b /a:-d /o:-d /t:c`) do (
if /I "%%f"=="%OldFile%" (Echo !!! Last file "%BoxIn%\%OldFile%". New file not created! &Exit /B 1)
start " " %Prg%
exit /B
)
echo !!! Folder Or Files "%BoxIn%\%Mask%" not found
exit /B 2