正如标题所示,我如何请求用户输入,如果不是字母goto:this。我正在制作一个批处理文件,以搜索指定的网络驱动器并返回.exe文件列表。
I have done this but with to much code, i.e.
If "%choice%"=="a" goto :scan
If "%choice%"=="b" goto :scan
etc.
谢谢!
@echo off
setlocal EnableDelayedExpansion
set letters=abcdefghijklmnopqrstuvwxyz
set /P drive=Enter drive:
rem Be sure that just one character is processed
set drive=%drive:~0,1%
rem Try to remove the character from letters;
rem if the result is not equal: the character IS a letter
if "!letters:%drive%=!" neq "%letters%" goto scan
使用VBScript可以更容易地完成此操作,但这里有一个批处理解决方案:
setlocal enabledelayedexpansion
set /p choice=
set map=abcdefghijklmnopqrstuvwxyz
for /l %%i in (0,1,25) do (
if /i %choice% equ !map:~%%i,1! goto scan
)
exit
:scan
@ECHO Off
SETLOCAL
SET letter=&SET /p letter="Please choose a single letter "
IF NOT DEFINED letter ECHO No choice made&GOTO :eof
ECHO "%letter%"|FINDSTR /i /b /e /r "[a-z]" >NUL
IF ERRORLEVEL 1 (ECHO NOT a single letter) ELSE (ECHO "%letter%" is a single letter)
几乎存在-只有当条目包含"
时才会出现故障