1

As the title suggests, How can I ask for user input and if it is not a letter goto :this. I am making a batch file to search a specified network drive and return a list of .exe files.

I have done this but with to much code, i.e. 
If "%choice%"=="a" goto :scan
If "%choice%"=="b" goto :scan
etc.

Thanks!

3 Answers 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
1
  • I can't seem to get it working... I will just go back to how I had it before. Thanks!
    – jabelone
    Commented Apr 9, 2013 at 10:09
1

You could do this easier with VBScript, but here's a batch solution:

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
1
  • I can't seem to get it working... I will just go back to how I had it before. Thanks!
    – jabelone
    Commented Apr 9, 2013 at 10:10
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)

Almost there - only appears to fail if entry contains "

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.