Basic Condition compare operators fail to work.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Basic Condition compare operators fail to work.

#1 Post by BoQsc » 08 Oct 2016 01:51

Why Lsize is not less or equal to Rsize?
It looks so basic, but LEQ seems to not work the way it should:
Output:
Is NOT LEQ
Press any key to continue . . .




Source code:

@echo off

set "Lsize=723840"
set "Rsize=29833438"


If [%Lsize%] LEQ [%Rsize%] echo Is LEQ
If Not [%Lsize%] LEQ [%Rsize%] echo Is NOT LEQ
pause

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Basic Condition compare operators fail to work.

#2 Post by dbenham » 08 Oct 2016 02:54

Because [ and ] are not digits, so it does a string comparison instead.

You need:

Code: Select all

If %Lsize% LEQ %Rsize% echo Is LEQ
If Not %Lsize% LEQ %Rsize% echo Is NOT LEQ


Dave Benham

Post Reply