Solved Batch file problem - Goto Was unexpected at this time

January 3, 2014 at 07:47:40
Specs: Windows 8,1
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 !


See More: Batch file problem - Goto Was unexpected at this time

Report •


✔ Best Answer
January 3, 2014 at 20:02:34
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 !



#1
January 3, 2014 at 09:01:42
I really can't help without the full source code, but according to the source here, there are no "ri" and "fix" labels. That may be causing the problem

message edited by thephantomblu


Report •

#2
January 3, 2014 at 09:12:34
I also wonder about the goto !. It seems like that would be an escapable charactor

::mike


Report •

#3
January 3, 2014 at 09:59:05
well,
@thephantomblu,
Im not sure what that means, so, Im just a young person.
Please may you help me out with that?

And,
@Mikelinus, Im Not sure Why it doesnt work.. I just hope someone will adres the problem for me.


Report •

Related Solutions

#4
January 3, 2014 at 12:32:45
remove the line @echo off, and see the last line that fails and the error.

on another note change the ! into exclamation, and then at the end of the batch file add this

:exclamation
:fix
:ri

::mike


Report •

#5
January 3, 2014 at 16:55:17
I assume the line "goto Uinstall" was just a typo on here for "goto Uninstall".

Always pop back and let us know the outcome - thanks

message edited by Derek


Report •

#6
January 3, 2014 at 20:02:34
✔ Best Answer
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 !


Report •

#7
January 4, 2014 at 07:02:04
@adam See this:

if %opt%== 2 goto Fix
if %opt%== 3 goto ri

Here, the gotos are not taking it anywhere, because there are no Fix and ri labels. For your understanding, :Fix and :ri do not exist.

Also, try this:

if [%opt%]==[1] goto Kill
if [%opt%]==[2] goto Fix
if [%opt%]==[3] goto ri
if [%opt%]==[4] exit


Report •


Ask Question