Batch file “批处理”对话框以选择要运行批处理的目录?

Batch file “批处理”对话框以选择要运行批处理的目录?,batch-file,directory,directory-structure,Batch File,Directory,Directory Structure,有没有办法显示一个对话框,允许用户选择在哪个目录下运行批处理?(从目录列表中,可能还有手动输入目录路径的选项?) 我可以想象它看起来像: echo Choose a directory to run script: SET /P ANS=Directory 1, 2, 3, 4, <etc> if /i {%ANS%}=={1} (goto :1) if /i {%ANS%}=={2} (goto :2) :: <etc> :1 <code to designat

有没有办法显示一个对话框,允许用户选择在哪个目录下运行批处理?(从目录列表中,可能还有手动输入目录路径的选项?)

我可以想象它看起来像:

echo Choose a directory to run script:
SET /P ANS=Directory 1, 2, 3, 4, <etc>
if /i {%ANS%}=={1} (goto :1)
if /i {%ANS%}=={2} (goto :2)
:: <etc>

:1
<code to designate directory to run in>
<code for operations>
:2
<etc>
echo选择要运行脚本的目录:
SET/P ANS=目录1,2,3,4,
if/i{%ANS%}={1}(转到:1)
if/i{%ANS%}={2}(转到:2)
:: 
:1
<指定要在其中运行的目录的代码>
<操作代码>
:2

但是我不知道如何指定目录。

使用CHOICE命令。用户可以输入一个数字,然后相应地设置ERRORLEVEL变量。有关更多详细信息,请参阅


编辑:另请参见问题中的字符串提示。

此代码段应该可以:

:start
set /p dir=Choose a directory: 
cls
if exist %dir% (cd %dir%) else echo Directory not found. & goto start
或者,如果您想从目录列表中进行选择:

echo Option 1
echo Option 2
echo Etc...
choice /c 123
::Replace "{directory}" with a folder path.
if errorlevel 3 cd {directory}
if errorlevel 2 cd {directory}
if errorlevel 1 cd {directory}
有无数种方式可供选择