Solved How to use if not batch in the same line twice?

April 14, 2014 at 12:53:42
Specs: Windows 7
How do I fix the below command so that even if one condition is false, the file "1.jpg" gets moved to c:\z\z and also renamed to 2.jpg
Putting & in between the 2 if commands crashes the batch and putting or in between doesnt help. With this current line the file gets moved and renamed only if both conditions are false. I need it to work if either of the 2 conditions are false and it need to work with just one single line as below. Thank you for your help.

if not 100 == 100 if not 200 == 200 move c:\z\1.jpg c:\z\z & rename c:\z\z\1.jpg 2.jpg

See More: How to use if not batch in the same line twice?

Report •

April 14, 2014 at 20:37:42
✔ Best Answer
Well, it would be better, IMO, if you used var.s instead of constants, to illustrate your situation (ie: there is never a situation where you would realistically compare a constant to a constant). But, in the spirit of things thus far:
if NOT 100*200 == 100*200 move c:\z\1.jpg c:\z\z\2.jpg

(also, there's no need to move a file, then rename it, since MOVE can perform both operations in one stroke)
Using variables, it might look like:
if %a%*%b% neq %c%*%d% move c:\z\1.jpg c:\z\z\2.jpg
or vars and constants:
if %a%*%b% neq 100*200 move c:\z\1.jpg c:\z\z\2.jpg

The asterisk can be any char used to separate the elements (space, _, etc ). With no separator, "10" and "0200" would be false positive, as would "1002" and "00".
at least, that's what i think might work, but I'm not totally sure at this point. (Staring at the screen too long...)

message edited by nbrane

Report •

April 18, 2014 at 13:18:48
Thats a great method using 100* 100 to make it work. Thanks.

Report •

Related Solutions

Ask Question