1

It's actually much longer than this. What is the better way to do this? I'm trying to write a decider that looks at files and determines which script to goto.

IF EXIST *x71c48* (GOTO script-a) else goto script-b
IF EXIST *x72c48* (GOTO script-a) else goto script-b
IF EXIST *x73c48* (GOTO script-a) else goto script-b
IF EXIST *x74c48* (GOTO script-a) else goto script-b
IF EXIST *x75c48* (GOTO script-a) else goto script-b
IF EXIST *x76c48* (GOTO script-a) else goto script-b
IF EXIST *x77c48* (GOTO script-a) else goto script-b
IF EXIST *x78c48* (GOTO script-a) else goto script-b
IF EXIST *x79c48* (GOTO script-a) else goto script-b
IF EXIST *x80c48* (GOTO script-a) else goto script-b
IF EXIST *x81c48* (GOTO script-a) else goto script-b
IF EXIST *x82c48* (GOTO script-a) else goto script-b
IF EXIST *x83c48* (GOTO script-a) else goto script-b
IF EXIST *x84c48* (GOTO script-a) else goto script-b
IF EXIST *x85c48* (GOTO script-a) else goto script-b
IF EXIST *x86c48* (GOTO script-a) else goto script-b
IF EXIST *x87c48* (GOTO script-a) else goto script-b
IF EXIST *x88c48* (GOTO script-a) else goto script-b
IF EXIST *x89c48* (GOTO script-a) else goto script-b
IF EXIST *s20c48* (GOTO script-a) else goto script-b
Ken White
  • 123,280
  • 14
  • 225
  • 444
blazin8s
  • 39
  • 4

1 Answers1

1

As your script is currently set, it will only execute the first line anyway. If you meant:

IF EXIST *x71c48* (
    GOTO script-a
) else IF EXIST *x72c48* (
    GOTO script-a
) else IF EXIST *x73c48* (
    GOTO script-a
) else IF...
rem etc. etc. etc.
... else goto script-b

... then you could shorten it with a findstr regular expression and conditional execution.

dir /b | findstr /i "x[0-9][0-9]c[0-9][0-9]" >NUL && goto script-a || goto script-b

You could also use a for /L loop.

setlocal enabledelayedexpansion
for /L %%I in (0,1,99) do (
    set "int=0%%I"
    if exist *x!int:~-2!c48* goto script-a
)
goto script-b
rojo
  • 24,000
  • 5
  • 55
  • 101