computing
  • 5

Solved Batch File Problem – Goto Was Unexpected At This Time

  • 5

Hi all, I have a goto problem, and an If Problem. I edited the batch, So It wont be open source.
Please help.
BATCH:
@echo off
cd XXX
If XXX Exist (
goto Uinstall
)
mkdir XXX
cd XXX
ECHO INSTALLING! PlEASE WAIT!
copy XXX
echo Please wait, Im creating a Short cut.
cd..
cd..
cd..
cd..
cd XXX
Echo “XXX” > Shortcut to XXX
echo thank you,
Echo this batch installer was created by Adam.
echo Please visit my site at XXX
echo press any key to exit
pause

:Uninstall
echo please choose the number that is located beside the option.

echo 1 – Uninstall
echo 2 – Fix
echo 3 – Reinstall
echo 4 – quit

set /p opt=:
if %opt%== 1 goto Kill
if %opt%== 2 goto Fix
if %opt%== 3 goto ri
if %opt%== 4 exit

:kill
Echo ARE YOU SURE YOU WANT TO DO THIS?
set /p opt=Y/N:
if %opt%== N exit
if %opt%==else goto !

Share

1 Answer

  1. line 1: you need to transpose to: IF EXIST XXX (
    line 2: like Derek said…
    line 7: copy XXX has no destination, so it does nothing and generates error.
    lines 9 etc.: might work, but relative paths are to be avoided, esp. for something like an “install”. If your install script doesn’t know where it is, it should just give up and abort.
    last line is an abomination. never use “!” in var. names, and if testing a variable for null, use any other method than that: IF “%opt%”==””, or best: IF NOT DEFINED OPT. but note that the second method requires that the var NOT have percents! Also, always set var to undefined before a set /p:
    set opt=
    set /p opt=:

    If XXX Exist (
    goto Uinstall
    )
    mkdir XXX
    cd XXX
    ECHO INSTALLING! PlEASE WAIT!
    copy XXX
    echo Please wait, Im creating a Short cut.
    cd..
    cd..
    cd..

    if %opt%==else goto !

    • 0