Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
918 views
in Technique[技术] by (71.8m points)

batch file - How to use spaces in "if"?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should also add quotes to variables.

if "%DriveDir%"=="NOT BOOT FILES" echo Working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...