批处理文件。如果用户输入一些东西找出它是哪一个
Batch File. If user enters something figure out which one it is
所以我正在制作一个打开特定信息的批处理文件,比如我想在我的批处理文件中打开需要用户输入的信息。例如文件 1、文件 2 和文件 3。
如果用户在用户输入区输入 File2,我希望它转到它,这是我第一次尝试编写代码。
:loggedin
echo Access Granted
echo Security Level 1
set /p select=Enter Password:%=%
::Checks the file the user is looking for
if "%select%"=="" (
cls
echo !NOTHING WAS INPUT INTO THE CONSOLE TRY AGAIN!
pause
goto :loggedin
) else (
if "select"=="file1"(
::User has input the file name. Show the content.
echo "Content of file 1"
) else (
if "select"=="file2"(
echo "Content of file2"
) else (
if "select"=="file3"(
echo "content of file three"
) else (
goto :loggedin
我知道这是非常错误的代码,但我很难绕过它我已经尝试了多种方法,但仍然无法通过它。
我可以使用 ERRORLEVEL 来解决这个问题吗?
变量必须用%
或!
括起来(以防延迟扩展)。您也可以使用/I
开关来代替IF
。并且没有else-if 中 bacth files.And 中括号中的构造块使用 REM 作为注释更安全:
:loggedin
echo Access Granted
echo Security Level 1
set /p select=Enter Password:%=%
::Checks the file the user is looking for
if "%select%"=="" (
cls
echo !NOTHING WAS INPUT INTO THE CONSOLE TRY AGAIN!
pause
goto :loggedin
)
if /I "%select%"=="file1" (
rem User has input the file name. Show the content.
echo "Content of file 1"
)
if /I "%select%"=="file2" (
echo "Content of file2"
)
if /i "%select%"=="file3"(
echo "content of file three"
)
goto :loggedin
else
有时很有用,但您在这里不需要它:
:loggedin
echo Access Granted
echo Security Level 1
set /p select=Enter Password:%=%
::Checks the file the user is looking for
if "%select%"=="" (
cls
echo !NOTHING WAS INPUT INTO THE CONSOLE TRY AGAIN!
pause
)
if /i "%select%"=="file1" (
::User has input the file name. Show the content.
echo "Content of file 1"
)
if /i "%select%"=="file2" (
echo "Content of file2"
)
if /i "%select%"=="file3" (
echo "content of file three"
)
goto :loggedin
此外:它说 "Access granted" 并要求您输入密码 之后 ?
我为 if
添加了 /i
以使其不区分大小写。
所以我正在制作一个打开特定信息的批处理文件,比如我想在我的批处理文件中打开需要用户输入的信息。例如文件 1、文件 2 和文件 3。
如果用户在用户输入区输入 File2,我希望它转到它,这是我第一次尝试编写代码。
:loggedin
echo Access Granted
echo Security Level 1
set /p select=Enter Password:%=%
::Checks the file the user is looking for
if "%select%"=="" (
cls
echo !NOTHING WAS INPUT INTO THE CONSOLE TRY AGAIN!
pause
goto :loggedin
) else (
if "select"=="file1"(
::User has input the file name. Show the content.
echo "Content of file 1"
) else (
if "select"=="file2"(
echo "Content of file2"
) else (
if "select"=="file3"(
echo "content of file three"
) else (
goto :loggedin
我知道这是非常错误的代码,但我很难绕过它我已经尝试了多种方法,但仍然无法通过它。
我可以使用 ERRORLEVEL 来解决这个问题吗?
变量必须用%
或!
括起来(以防延迟扩展)。您也可以使用/I
开关来代替IF
。并且没有else-if 中 bacth files.And 中括号中的构造块使用 REM 作为注释更安全:
:loggedin
echo Access Granted
echo Security Level 1
set /p select=Enter Password:%=%
::Checks the file the user is looking for
if "%select%"=="" (
cls
echo !NOTHING WAS INPUT INTO THE CONSOLE TRY AGAIN!
pause
goto :loggedin
)
if /I "%select%"=="file1" (
rem User has input the file name. Show the content.
echo "Content of file 1"
)
if /I "%select%"=="file2" (
echo "Content of file2"
)
if /i "%select%"=="file3"(
echo "content of file three"
)
goto :loggedin
else
有时很有用,但您在这里不需要它:
:loggedin
echo Access Granted
echo Security Level 1
set /p select=Enter Password:%=%
::Checks the file the user is looking for
if "%select%"=="" (
cls
echo !NOTHING WAS INPUT INTO THE CONSOLE TRY AGAIN!
pause
)
if /i "%select%"=="file1" (
::User has input the file name. Show the content.
echo "Content of file 1"
)
if /i "%select%"=="file2" (
echo "Content of file2"
)
if /i "%select%"=="file3" (
echo "content of file three"
)
goto :loggedin
此外:它说 "Access granted" 并要求您输入密码 之后 ?
我为 if
添加了 /i
以使其不区分大小写。