Reputation: 13
I'm trying to see if a string is the same as another string by using if, but the string contains spaces!
It looks something like this:
if %DriveDir%==NOT BOOT FILES echo Working
Simply put, it says "BOOT was unexpected at this time"
if %DriveDir%=="NOT BOOT FILES" echo Working
if %DriveDir%==%nbf% echo Working
I have tried using quotes and storing the string in a variable like this, but nothing changes.
Upvotes: 1
Views: 64
Reputation: 2942
batch file interpretation is very literal. you are not really using variables, they all get replaced with their values on load. so the line
if %DriveDir%=="NOT BOOT FILES" echo Working
gets expanded to
if NOT BOOT FILES=="NOT BOOT FILES" echo Working
which is obviously syntactically incorrect. you need to have the same expression on both sides, and the NOT
gets parsed as IF NOT…
, so you need to surround both wih quotes.
Upvotes: 0
Reputation: 7727
You should also add quotes to variables.
if "%DriveDir%"=="NOT BOOT FILES" echo Working
Upvotes: 3