我正在尝试制作一个包含一些名称的菜单。每个名称都将用一个数字表示。 如果我输入号码。它将打开 youtube 或 google。
我可以使用 (goto) 选项来执行此操作,但在本例中,我尝试将 droploc 一词替换为 youtube 或 google 等。可能吗?
@echo off
@echo menu
@echo enter 1 for google
@echo enter 2 for youtube
set google=1
set youtube=2
REM Example 1
if "%1%" == "1" (
set dropLoc=1
)
echo %dropLoc%
start "link" "https://dropLoc
最佳答案
您不会提示输入要处理的值。尝试以下操作,它应该可以帮助您入门。
@echo off
:Menu
@echo menu
@echo enter 1 for google
@echo enter 2 for youtube
REM Prompt user to enter a value.
SET /P Selection=Enter selection:
SET dropLoc=null
REM Set the dropLoc based on the user selection.
IF "%Selection%" == "1" SET dropLoc=www.google.com
IF "%Selection%" == "2" SET dropLoc=www.youtube.com
REM If no valid selection, send the user back to the menu.
IF "%dropLoc%" == "null" (
ECHO Enter a valid selection.
GOTO Menu
)
echo %dropLoc%
start "link" "https://%dropLoc%
关于windows - 批处理文件 - 将变量设置为 “if” 然后 "set",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27637829/