0

Why does the second if statement return true?

Script:

set test=Mumbai Short Call Agentwise-MUMBAI SHORT CALL-%1
for /f "tokens=1,2,3,4,5 delims=-." %%a in ('dir /b %c2cpath%\IN *-*-*-*.*') do (
  set temp=%%d
  if %date%==!temp! (
    set tempfilename=%%a-%%b-%1
    if !tempfilename!==%test%(
      set filename=%%a-%%b-%%c-%1
      echo !filename!
    )
  ) 
)
Tushar
  • 25
  • 8
  • 4
    The problem is the if statemet comparing a string with spaces without quoting it. And as @Samuel mentions there is a `Setlocal EnableDelayedExpansion` missing. –  Feb 25 '17 at 12:43
  • You also need a space between the string comparison and the left parentheses. – Squashman Feb 25 '17 at 23:47
  • The dir command will process the two elements `%c2cpath%\IN` and `*-*-*-*.*` independently, I guess there should be a backslash between them. –  Feb 26 '17 at 16:44
  • where should I put that "Setlocal EnableDelayedExpansion" . And I need a space between the string comparison and left parentheses. File name is like these "ABC-XYZ SHORT CALL-2-11092016". Date is appended at the end of the file like here 11092016. Here my query is that if run these batch with specific date. That date file will only come with specified name in for loop. Please tell me as early as possible. because I am new to these batch-file. – Tushar Feb 27 '17 at 07:02
  • @Roy in most cases you set `Setlocal EnableDelayedExpansion` on the top of your script (see for example answers to [this question](https://stackoverflow.com/questions/10558316/example-of-delayed-expansion-in-batch-file)). – J.Baoby Feb 28 '17 at 11:29
  • Also the `%date%` variable is a built-in variable that expands to the current date in the same format as the output of [`date /t`](https://ss64.com/nt/date.html) that depends on locale settings. Seeing the comment above, I suppose that's not what you want and you've set the `%date%` variable with your own value. I would recommend you to use another variable name so the `%date%` variable can still keep its original function. See [this page](https://ss64.com/nt/syntax-variables.html) for a list of some built in environment variabled. – J.Baoby Feb 28 '17 at 11:39

0 Answers0