0
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?

2 Answers2

0

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
Gerhard
  • 22,678
  • 7
  • 27
  • 43
-1

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

David Brunning
  • 575
  • 7
  • 18
  • If some operation success,I only want to generate done.txt.If the operation fails,then I only want to generate fail.txt.what I don`t understand is 11 is not equals 0,why the statement "cd.>fail.txt" is executed – user6630815 Nov 23 '17 at 08:06
  • @user6630815: double check. It isn't. – Stephan Nov 23 '17 at 08:15