The syntax of the command is incorrect - IF Statement Batch

I am trying to execute below function in batch but I am receiving an error in the IF statement, I've been trying to fix this but no luck.

:Method2
set File=%1
set Filename=%2
echo %Filename%
pause
IF NOT x%Filename:Test=% == x%Filename%
(
    File >> File_List.txt
)

exit /b 2

:End

I know the issue is in the IF statement, been debugging the issue but can't find the correct syntax for the code. After this I want to replace that "Test" to be a input parameter from the user so it can be any specific word, I want to make it look something like this...

IF NOT x%Filename:%Input%=% == x%Filename%

Could you please help?

Upvotes: 1

Views: 4595

Answers (2)

I've found a solution for my problem, yes, basically the "(" needed to be on the end of the IF and it solved that issue, for the parameter issue, I found below solution which works perfectly fine.

:Method2
set File=%1
set Filename=%2
set param=%3
IF NOT "!Filename:%param%=!"=="%Filename%" (
    echo %File% >> File_List.txt
    echo %File% moved
)

Upvotes: 3

Sam Denty
Sam Denty

Reputation: 4085

:Method2
set "File=%1"
set "Filename=%2"
echo %Filename%
set /p "test=: "
pause
IF NOT "%Filename%%test%" == "%Filename%" (
    File >> File_List.txt
)

exit /b 2

:End

Upvotes: 1

Related Questions