我该如何从用户那里获取输入,然后根据该输入更改目录。
示例,假设我问,请输入A目录 按Enter键时,目录应更改为该目录,并将工作目录回显给用户。
@ECHO OFF
:: This batch file takes input from the user, delete, copy and install
new files.
ECHO Please enter the location of your Zibo folder:
set mydir=%CD%
PAUSE
ECHO your working directory is:
ECHO %mydir%
PAUSE
答案 0 :(得分:2)
您可以使用Set /P
请求用户输入。要了解操作方法,请在命令提示符下输入set /?
,然后阅读输出。要更改目录,您可以使用CD|ChDir
,输入cd /?
时,命令提示符也会提供其使用信息。
这是一个例子:
@Echo Off
:GetInput
Set "ZiboDir="
Rem Request input from the user.
Set /P "ZiboDir=Please enter the location of your Zibo directory: "
If Not Defined ZiboDir GoTo GetInput
If Not Exist "%ZiboDir%\" GoTo GetInput
Echo Your Zibo directory is %ZiboDir%
Pause
Rem Make the Zibo directory the current directory
CD /D "%ZiboDir%"
Echo Your current directory is %CD%
Pause