Error Message Help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Error Message Help

#1 Post by alleypuppy » 05 May 2011 19:56

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:

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Error Message Help

#2 Post by aGerman » 06 May 2011 13:45

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

alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Re: Error Message Help

#3 Post by alleypuppy » 06 May 2011 19:45

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.

Post Reply