promotion image of download ymail app
Promoted
Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

How do you make an else if statement in Batch file?

I am trying to make my batch file do something like this:

IF keylogger.exe is found {

del keylogger.exe

}

Else you have no viruses

I am trying to make it so that if the BATCH file finds a certain file, it will delete it

please help

4 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    In this example, the batch will search to see if you have foo.txt in your local disk:

    @echo off

    if exist "C:\foo.txt" (

    echo "C:\foo.txt" was found.

    pause >nul

    exit

    )

    echo "C:\foo.txt" was not found.

    pause >nul

    exit

    Next example: This one uses labels

    @echo off

    echo.

    set /p num1=Enter a number:

    echo.

    set /p num2=Enter another number:

    echo.

    if %num1%==%num2% goto true

    if not %num1%==%num2% goto false

    :true

    echo The two numbers you entered were the same.

    echo.

    pause

    exit

    :false

    echo The two numbers you entered were different.

    echo.

    pause

    exit

    Next Example: this will search for keylogger.exe in a few folders:

    @echo off

    rem You can change this variable to another

    rem file to search for:

    Set file=keylogger.exe

    echo.

    cd "C:\"

    if exist "%file%" echo %file% found: C:\

    if not exist "%file%" echo %file% not found: C:\

    cd "C:\Windows"

    if exist "%file%" echo %file% found: C:\Windows

    if not exist "%file%" echo %file% not found: C:\Windows

    set sys32=C:\Windows\System32

    cd "%sys32%"

    if exist "%file%" echo %file% found: %sys32%

    if not exist "%file%" echo %file% not found: %sys32%

    cd "%userprofile%"

    if exist "%file%" echo %file% found: %userprofile%

    if not exist "%file%" echo %file% not found: %userprofile%

    cd "%temp%"

    if exist "%file%" echo %file% found: %temp%

    if not exist "%file%" echo %file% not found: %temp%

    cd "%appdata%"

    if exist "%file%" echo %file% found: %temp%

    if not exist "%file%" echo %file% not found: %temp%

    echo.

    pause

    exit

    • Commenter avatarLogin to reply the answers
  • Erika
    Lv 4
    3 years ago

    If Statement Batch

    • Commenter avatarLogin to reply the answers
  • saleh
    Lv 4
    3 years ago

    Windows Batch If Else

    • Commenter avatarLogin to reply the answers
  • 5 years ago

    This Site Might Help You.

    RE:

    How do you make an else if statement in Batch file?

    I am trying to make my batch file do something like this:

    IF keylogger.exe is found {

    del keylogger.exe

    }

    Else you have no viruses

    I am trying to make it so that if the BATCH file finds a certain file, it will delete it

    please help

    Source(s): statement batch file: https://shortly.im/TPi4E
    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.