if 0 NEQ 0 cd.>done.txt
if 11 EQU 0 cd.>fail.txt
pause
This is a bat file,when i run it,both done.txt and fail.txt generated.But I want only generate done.txt. It means I want generate different file according different case.What shall i do?
if 0 NEQ 0 cd.>done.txt
if 11 EQU 0 cd.>fail.txt
pause
This is a bat file,when i run it,both done.txt and fail.txt generated.But I want only generate done.txt. It means I want generate different file according different case.What shall i do?
Try this.
@echo off
set var=11
set var2=0
if %var%==%var2% (
echo %var% is %var2% >done.txt
) else (
echo %var% is not %var2% >fail.txt)
pause
You can change the value of var
and var2
to see the different files.
So by using your scenario we can replace the echo strings with:
@echo off
set var=11
set var2=0
if %var%==%var2% (
cd. >done.txt
) else (
cd. >fail.txt)
pause
Looks like you want to do an OR statement, so that if either result is true the output is piped to done.txt. Is that right?
Have a look at the answer here for a neat solution: IF... OR IF... in a windows batch file