带有错误检查的多选菜单

时间:2014-05-27 11:17:00

标签: function batch-file menu

好的所以我写了这个脚本并且它有效,但是我已经欺骗了它并为错误检查做了一些小狗函数。检查完命令后,我找不到任何可以检查是否存在的选项:

@echo off

Echo Below are a list of options please select one. Mulople options can 
Echo be entered provided that they are seperated by a spaceor comma (,) 
Echo eg. 1,2,3 1 or 1 2 3
Echo Available Options:
Echo Option 1 
Echo Option 2
Echo Option 3

SET /P Selection=Please enter Option? 
SET String=%Selection%
echo You have chosen: %Selection% 

Call :ErrorChecker
Echo Options have been Varified
Call :Process
pause

goto :EOF

:ErrorChecker
Rem This is an error checker to check if a Function exists this does not actually check the :Opt function but each 
Rem :Exist Function there for each :Opt Function must have a corresponding :Exist   function or it will not run.
Rem WARRNING Each :Opt Function must have a corresponding Empty :Exist Function or this Script will error.
for %%A in (%Selection%) do (
Call :Exist%%A 2>NUL
if errorlevel 1 (
SET /P Selection= There where errors in the Selection %String%, Please choose Valid                   
Options:
goto :ErrorChecker
)
)
goto :EOF

:Process
Echo !STARTING RESTORE!
for %%A in (%Selection%) do (
Call :Opt%%A
)
GOTO :EOF

:Exist1
Rem this is apart of error checker and corresponds to the :opt Function below.
Rem !!!DO NOT PLACE CODE HERE!!!
exit /B 0
:Opt1
ECHO Option 1's code
exit /B 0

:Exist2
Rem this is apart of error checker and corresponds to the :opt Function below.
Rem !!!DO NOT PLACE CODE HERE!!!
exit /B 0
:Opt2
ECHO Option 2's code
exit /B 0

:Exist3
Rem this is apart of error checker and corresponds to the :opt Function below.
Rem !!!DO NOT PLACE CODE HERE!!!
exit /B 0
:Opt3
ECHO Option 3's code
exit /B 0

我知道有一些狡猾的事情,但它起作用。

0 个答案:

没有答案