Page 1 of 1

Error Message Help

Posted: 05 May 2011 19:56
by alleypuppy
Hello,

I am working on a batch file and I need help with error messages. I want to make it so if I type in something invalid, the file echoes "Unknown Command!", if I type in "cd /" it goes to the root "directory" that I made in the file, and if I type in "cd [something invalid]", the file will echo "Invalid Path!".

My question is how do I get the file to echo "Invalid Path!" only if I type in something like "cd ggthmk", but make the file echo "Unknown Command!" if anything else invalid is typed.

Here is an example version of the file that illustrates my problem:

@echo off
:/home/
set /p command=$
if /I "%command%"=="cd /" goto cd /
if /I "%command%"=="exit" exit
echo Unkown Command!
goto /home/
:cd /
echo.
echo The current directory is now /
echo.
goto /
:/
set /p command=$
if /I "%command%"=="cd home" goto cd /home/
if /I "%command%"=="exit" exit
echo Unkown Command!
goto /
:cd /home/
echo.
echo The current directory is now /home/
echo.
goto /home/
::-------END-------

Thanks for any help guys! :wink:

Re: Error Message Help

Posted: 06 May 2011 13:45
by aGerman
Don't use spaces in labels. :cd / and :cd /home/ is the same for the command interpreter. You could replace the spaces by underlines.

Maybe you could call each label as a sub routine to make it work. Return to the calling line using goto :eof

Regards
aGerman

Re: Error Message Help

Posted: 06 May 2011 19:45
by alleypuppy
Okay I will try that. :wink:

And I know about spaces in labels (I found out the hard way!). I was just using this as an example.