jeudi 24 août 2017

Why can't I nest an if exist statement inside this code in a batch/cmd file

I am currently writing a short command line utility to quickly install/uninstall programs and need to first identify that installation files exist to give a meaningful error message in the event that conditions aren't met.

I currently have the below code written

@echo off
setlocal EnableExtensions

echo.
echo 1.Run Program1
echo 2.Summit else
echo 3.Summit else
echo 4.Summit else
echo 5.Summit else
echo.

set /p a= Enter Choice: 

if %a%==1(
if exist program1.cmd(
    rem program1 exists
    echo "Run program1.cmd"
    ) else(
    rem program1 does not exist
    echo "program1 does not exist"
    ))
pause

I am currently told "The syntax of the command is incorrect." regardless of whether Program.cmd exists or not but I don't understand why.

Is nesting if commands not possible in batch/cmd files or do I fundamentally misunderstand something in the syntax of windows command-line.

Aucun commentaire:

Enregistrer un commentaire