Use lss
instead of leq
. So we will have "less than", "greater than" and "equal to", which seems to be what you want.
The correct method of using else
in this instance would be:
if !DATE1! gtr !DATE2! (
echo "!FILE1:\=!" is newer than "!FILE2:\=!"
) else if !DATE1! lss !DATE2! (
echo "!FILE1:\=!" is older than "!FILE2:\=!"
) else if !DATE1! equ !DATE2! (
echo "!FILE1:\=!" is same with "!FILE2:\=!"
)
However, We do not need else
in this instance as each line will be evaluated until one returns true, so you could just do:
if !DATE1! gtr !DATE2! echo "!FILE1:\=!" is newer than "!FILE2:\=!"
if !DATE1! lss !DATE2! echo "!FILE1:\=!" is older than "!FILE2:\=!"
if !DATE1! equ !DATE2! echo "!FILE1:\=!" is same with "!FILE2:\=!"
I suggest you read the help, open cmd.exe
and run:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…