我正在为 Windows 制作一个批处理文件。我刚刚开始学习批处理脚本,这里遇到了一些问题。
@echo off
set langList=("eng","fre","chi")
:Get_ISOlanguage
set "ISOlanguage="
set /p ISOlanguage=Enter subtitle language in ISO 639-2 standard abbreviation:
set ISOlanguage="%ISOlanguage%"
for %%x in %langList% do (
if ""%ISOlanguage%"" == ""%%x"" (echo LANGUAGE SUPPORTED
goto :CONTINUE))
echo LANGUAGE NOT SUPPORTED
goto :GET_ISOlanguage
:CONTINUE
echo ayy lmao
pause
代替
for %%x in %langList% do (if ""%ISOlanguage%"" == ""%%x"" (echo LANGUAGE SUPPORTED&goto :CONTINUE))
如果用户输入 eg,eng
我该如何获取 egYour chosen language is English
然后继续批处理?如果用户输入的内容不在 langList 中,我想显示一条错误消息,提示“输入错误,请重试”。
答案1
我以为我读到过某个地方你想将列表保存在批处理文件中而不是数据文件中。最明显的解决方案是定义大量变量,但我更喜欢另一种方法:
@echo off
:Get_ISOlanguage
set "language=not supported"
set /p "ISOlanguage=Enter language code: "
for /f "tokens=3 delims=," %%i in ('find "DATA,%ISOlanguage%," "%~f0"') do set language=%%i
echo language is %language%
if "%language%"=="not supported" goto :Get_ISOlanguage
goto :eof
DATA,eng,English
DATA,fre,French
DATA,chi,Chinese
DATA,ger,German
DATA,deu,German
DATA,chn,Chinook jargon