【问题标题】:Batch dialogue to choose directory to run batch?批处理对话框选择要运行批处理的目录?
【发布时间】:2013-03-21 20:50:09
【问题描述】:

是否有任何方法可以显示允许用户选择在哪个目录中运行批处理的对话框? (来自目录列表,也许是手动输入目录路径的选项?)

我想它会是这样的:

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>

但我不确定如何指定目录。

【问题讨论】:

    标签: batch-file directory directory-structure


    【解决方案1】:

    使用 CHOICE 命令。用户可以输入一个数字,然后相应地设置 ERRORLEVEL 变量。详情请见here

    编辑:另请参阅this 字符串提示问题。

    【讨论】:

      【解决方案2】:

      这个 sn-p 应该很有魅力:

      :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}
      

      有无数种方式可供选择。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-25
        • 2015-11-24
        • 2012-06-19
        • 2021-11-08
        • 1970-01-01
        • 2011-07-20
        相关资源
        最近更新 更多