1.

Solve : If then else in DOS?

Answer» <html><body><p>Hi All,<br/><br/>I am trying to <a href="https://interviewquestions.tuteehub.com/tag/write-746491" style="font-weight:bold;" target="_blank" title="Click to know more about WRITE">WRITE</a> a bat file that should check for a particular entry within a file. On <a href="https://interviewquestions.tuteehub.com/tag/finding-989059" style="font-weight:bold;" target="_blank" title="Click to know more about FINDING">FINDING</a>, it should proceed to the next step or terminate right there. <br/><br/>I have managed to put in the following piece of code but it's not helping me with what I want to do:<br/><br/> Code: <a>[Select]</a>ECHO OFF<br/>REM========================================<br/><br/>SET LOG=\tmp\check.log<br/><br/>REM ====================================================<br/>REM 1) Check for entry "A"<br/>REM ====================================================<br/>E:<br/><a href="https://interviewquestions.tuteehub.com/tag/cd-236847" style="font-weight:bold;" target="_blank" title="Click to know more about CD">CD</a> \ABC<br/><br/>IF EXIST temp.log.(FINDSTR "A" temp.log.)ELSE echo temp.log. missing &gt;&gt;%LOG%<br/>IF %ERRORLEVEL% NEQ <a href="https://interviewquestions.tuteehub.com/tag/0-242464" style="font-weight:bold;" target="_blank" title="Click to know more about 0">0</a> ( <br/>ECHO <a href="https://interviewquestions.tuteehub.com/tag/failed-2080748" style="font-weight:bold;" target="_blank" title="Click to know more about FAILED">FAILED</a> to find entry A in temp.log &gt;&gt;%LOG%<br/>goto EXITERROR ) ELSE (<br/>goto step2<br/>)<br/><br/>REM ====================================================<br/>REM 2) Check for entry "B"<br/>REM ====================================================<br/>:step2<br/>E:<br/>cd \ABC<br/><br/>IF EXIST temp.log.(FINDSTR "B" temp.log.)ELSE echo temp.log. missing &gt;&gt;%LOG%<br/>IF %ERRORLEVEL% NEQ 0 ( <br/>ECHO Failed to find entry B in temp.log &gt;&gt;%LOG%<br/>goto EXITERROR ) ELSE (<br/>goto step3<br/>)<br/><br/>REM ====================================================<br/>REM 3) Check for entry "C"<br/>REM ====================================================<br/>:step3<br/>E:<br/>cd \ABC<br/><br/>IF EXIST temp.log.(FINDSTR "C" temp.log.)ELSE echo temp.log. missing &gt;&gt;%LOG%<br/>IF %ERRORLEVEL% NEQ 0 ( <br/>ECHO Failed to find entry C in temp.log &gt;&gt;%LOG%<br/>goto EXITERROR ) ELSE (<br/>ECHO All entries found in the file&gt;&gt;%LOG%<br/>)<br/><br/>REM ==========================<br/>REM ERROR Code<br/>REM ==========================<br/>:EXITERROR<br/>The file temp.log resides under the folder ABC under E: drive. I want to check for the entry "A" within this file before proceeding with the next step. The script should simply go to the next step if it finds, otherwise it should exit by alerting the user.<br/><br/>Please can you help? I am testing this on Windows 2003 Server.<br/><br/>Many thanks<br/><br/>No need to double post. I'm locking this thread.</p></body></html>


Discussion

No Comment Found