0
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

SET _STRING=image.pdf
SET _TEXT=.Pf

REM if delete next line
REM IF /I %_STRING:%_TEXT%=% NEQ %_STRING%  (ECHO. 'not equal') ELSE (ECHO. 'equal')

REM and insert value instead of variable
IF /I %_STRING:.Pf=% NEQ %_STRING%  (ECHO. 'not equal') ELSE (ECHO. 'equal')

PAUSE
GOTO :EOF

Now output is correct

'equal'
Compo
  • 36,585
  • 5
  • 27
  • 39
  • 3
    remove `echo off` and watch how the code is executed. Then read about [delayed expansion](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected/30284028#30284028) – Stephan Jan 18 '21 at 17:21
  • 3
    `IF /I NOT "!_STRING:%_TEXT%=!" == "%_STRING%"` would be my first assumption! – Compo Jan 18 '21 at 17:56
  • @Compo line is correct, and I accepted in my batch, thanks – Adel M. itani Jan 18 '21 at 21:08
  • Now my batch is correct, by using @Compo line. – Adel M. itani Jan 18 '21 at 21:30
  • I have rolled back your edit, please do not change it to add an answer in the question area. If you want to post an answer yourself, please feel free to do so. Although it would have been more courteous to give me the chance to convert my comment to an answer for you! Please also learn how to format your question, and any answer, I should not have to keep on editing your lack of formatting, especially of your code. – Compo Jan 18 '21 at 21:31

1 Answers1

0

Here's my comment reproduced as an answer, together with the recommended syntax for defining variables using the SET command.

@ECHO OFF
SETLOCAL DISABLEDELAYEDEXPANSION
    
    SET "_STRING=image.pdf"
    SET "_TEXT=.Pf"
    
    SETLOCAL ENABLEDELAYEDEXPANSION
        
        IF /I NOT "!_STRING:%_TEXT%=!" == "%_STRING%" (ECHO= 'not equal') ELSE ECHO= 'equal'
        
    ENDLOCAL
    
    PAUSE
    
GOTO :EOF

I have also indented the code, to better highlight the sections which are working under different levels of SETLOCAL.

Compo
  • 36,585
  • 5
  • 27
  • 39