感谢您关注我的问题。
我在给定目录中有五个配置文件。在我的批处理脚本中,我想读取这些文件名并将其提示给用户。用户选择配置文件后,从中读取变量。
任何人都可以在这里帮助我一些逻辑。所以,我可以把它推进去。
谢谢。
答案 0 :(得分:1)
这样的批处理或.cmd
文件演示了菜单技术(没什么特别的,用户必须准确输入文件名)。关键项目:
FOR
SET /P
IF EXIST
祝你好运!
@echo off
REM Show the user the list and ask them which one to use
echo.
echo Please select one of:
echo.
for %%F in ("D:\A Given Directory\*.config") do echo %%~nxF
echo.
set SEL_CFGFNM=
set /P SEL_CFGFNM=Which configuration file:
REM Make sure they answered, and that the file exists
if "%SEL_CFGFNM%" == "" goto ENDIT
if NOT EXIST "D:\A Given Directory\%SEL_CFGFNM%" goto NOCFG
REM User has selected file "D:\A Given Directory\%SEL_CFGFNM%" and it exists
REM Do whatever you want to do with that file now
REM Don't fall through the exit messages
goto ENDIT
REM Exit Messages
:NOCFG
echo.
echo ERROR: Configuration file "%SEL_CFGFNM%" is not on the list
echo.
goto ENDIT
REM Cleanup
:ENDIT
set SEL_CFGFNM=