This is a very basic example of what I am trying to implement in a more complex batch file. I would like to extract a substring from an input parameter (%1
) and branch based on if the substring was found or not.
@echo off
SETLOCAL enableextensions enabledelayedexpansion
SET _testvariable=%1
SET _testvariable=%_testvariable:~4,3%
ECHO %_testvariable%
IF %_testvariable%=act CALL :SOME
IF NOT %_testvariable%=act CALL :ACTION
:SOME
ECHO Substring found
GOTO :END
:ACTION
ECHO Substring not found
GOTO :END
ENDLOCAL
:END
This is what my output looks like:
C:\>test someaction
act
=act was unexpected at this time.
If possible I would like to turn this in to a IF/ELSE statement and evaluate directly from %1
. However I have not had success with either.