DOS Batch IF statement problems

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jinkskgpt
Posts: 2
Joined: 12 Sep 2011 11:26

DOS Batch IF statement problems

#1 Post by jinkskgpt » 12 Sep 2011 11:47

I have a really weird problem. It is almost like there is some setting in my cmd prompt window environment that is making the IF command work incorrectly.

here is the cmd file I am trying to run:

Code: Select all

@echo off
set str1="Default Web Site"
set str2="Default Web Site"
echo %str1%
echo %str2%

REM @echo on
IF /I (%str1% EQU %str2%) (
echo %_WebSiteName% Found bsw!
goto :siteFound
)
echo %_WebSiteName% NOT Found bsw!
:siteFound
echo.
pause

Every time I run this the IF command evaluates to FALSE. Now that's NOT supposed to happen: especially when you Hardcode both variable.

Any help will be appreciated!

Bob D
Posts: 20
Joined: 07 Sep 2011 18:32
Location: Eastern Australia

Re: DOS Batch IF statement problems

#2 Post by Bob D » 13 Sep 2011 04:11

get rid of the quotes from the content of str1 and str2 and put them around the variables when doing the comparison.
Variables with included blanks need to be enclosed with quotes when comparing.

Code: Select all

set str1=Default Web Site
set str2=default web site
IF /I "%str1%" EQU "%str2%" (echo found) else (echo not found)

Post Reply