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!
Error Message Help
Moderator: DosItHelp
Re: Error Message Help
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
Maybe you could call each label as a sub routine to make it work. Return to the calling line using goto :eof
Regards
aGerman
-
- Posts: 82
- Joined: 24 Apr 2011 19:20
Re: Error Message Help
Okay I will try that.
And I know about spaces in labels (I found out the hard way!). I was just using this as an example.
And I know about spaces in labels (I found out the hard way!). I was just using this as an example.