Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: If then else in DOS  (Read 12962 times)

0 Members and 1 Guest are viewing this topic.

swados

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Unknown
    If then else in DOS
    « on: December 14, 2010, 06:16:03 AM »
    Hi All,

    I am trying to write a bat file that should check for a particular entry within a file. On finding, it should proceed to the next step or terminate right there.

    I have managed to put in the following piece of code but it's not helping me with what I want to do:

    Code: [Select]
    @ECHO OFF
    REM========================================

    SET LOG=\tmp\check.log

    REM ====================================================
    REM 1) Check for entry "A"
    REM ====================================================
    E:
    cd \ABC

    IF EXIST temp.log.(FINDSTR "A" temp.log.)ELSE echo temp.log. missing >>%LOG%
    IF %ERRORLEVEL% NEQ 0 (
    ECHO Failed to find entry A in temp.log >>%LOG%
    goto EXITERROR ) ELSE (
    goto step2
    )

    REM ====================================================
    REM 2) Check for entry "B"
    REM ====================================================
    :step2
    E:
    cd \ABC

    IF EXIST temp.log.(FINDSTR "B" temp.log.)ELSE echo temp.log. missing >>%LOG%
    IF %ERRORLEVEL% NEQ 0 (
    ECHO Failed to find entry B in temp.log >>%LOG%
    goto EXITERROR ) ELSE (
    goto step3
    )

    REM ====================================================
    REM 3) Check for entry "C"
    REM ====================================================
    :step3
    E:
    cd \ABC

    IF EXIST temp.log.(FINDSTR "C" temp.log.)ELSE echo temp.log. missing >>%LOG%
    IF %ERRORLEVEL% NEQ 0 (
    ECHO Failed to find entry C in temp.log >>%LOG%
    goto EXITERROR ) ELSE (
    ECHO All entries found in the file>>%LOG%
    )

    REM ==========================
    REM ERROR Code
    REM ==========================
    :EXITERROR

    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.

    Please can you help? I am testing this on Windows 2003 Server.

    Many thanks


    Allan

    • Moderator

    • Mastermind
    • Thanked: 1260
    • Experience: Guru
    • OS: Windows 10
    Re: If then else in DOS
    « Reply #1 on: December 14, 2010, 12:52:47 PM »
    No need to double post. I'm locking this thread.