1

正如标题所暗示的,我如何询问用户输入,如果它不是字母 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.

谢谢!

4

3 回答 3

3
@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
于 2013-04-09T09:51:53.400 回答
1

您可以使用 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
于 2013-04-09T09:35:40.517 回答
1
@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)

几乎就在那里 - 仅当条目包含时才会出现失败"

于 2013-04-09T14:11:31.483 回答