如何使用FIND语句以及嵌套的IF条件

时间:2015-10-13 07:34:44

标签: batch-file if-statement

我试图批量使用find语句和if条件,但执行不会进入if条件,它会在第一个if停止声明:

@echo off  
find /i "DA" E:\LogFiles_List.txt > nul  
pause  
if errorlevel 1  
(  
echo DA not found  
pause    
)  
else  
(  
find /i "Error" E:\hello.txt > nul   
 if errorlevel 0 (   
 echo Error found in hello.txt   
pause  
 ) else (   
 echo Error NOT found in thefile.txt   
pause  
 )   
)  

1 个答案:

答案 0 :(得分:0)

研究if中描述的if /?语法。 parantheses必须与ifelse在同一行。这是更正后的代码:

@echo off  
find /i "DA" E:\LogFiles_List.txt > nul  
pause  
if errorlevel 1 (  
  echo DA not found  
  pause    
) else (  
  find /i "Error" E:\hello.txt > nul   
  if errorlevel 0 (   
    echo Error found in hello.txt   
    pause  
  ) else (   
    echo Error NOT found in thefile.txt   
    pause  
  )   
)