I am writing a batch script where if user input is empty or doesnot ends with “DTO” I need to ask user to enter DTO name again.
:INPUT
SET /P INPUTDTO=Enter the DTO:
IF "%INPUTDTO%"=="" (
IF "%INPUTDTO%" ??????? (
GOTO NODTO
)
)
:NODTO
ECHO ERROR: Please enter a valid DTO.
GOTO INPUT
How to check if the user input ends with “DTO”
The existing INPUTDTO value should probably be cleared because SET /P will preserve the existing value if the user does not enter anything.
Add the
/Iswitch to the IF statement if you want the comparison to be case insensitive.