我如何浓缩这个? [英] How do I condense this?

查看:170
本文介绍了我如何浓缩这个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上比这更长。有什么更好的方法来做到这一点?我试图写一个决定器,看看文件,并确定哪个脚本转到。

$ pre $如果存在x71c48 *(GOTO脚本-a)其他goto脚本-b
如果存在* x72c48 *(GOTO脚本-a)否则转到脚本-b
如果存在* x73c48 *(GOTO脚本-a)否则转到脚本-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脚本-a)其他转到脚本-b
如果存在* x77c48 *(GOTO脚本-a)否则转到脚本-b
如果存在* x78c48 *(GOTO脚本-a)否则转到脚本-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脚本-a)其他转到脚本-b
如果存在* x82c48 *(GOTO脚本-a)否则转到脚本-b
如果存在* x83c48 *(GOTO脚本-a)否则转到脚本-b
IF EXIST * x84c48 *(GOTO script -a)else goto script -b
IF EXIST * x85c48 *(GOTO script -a)else goto script -b
IF EXIST * x86c 48 *(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


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

...那么你可以用 findstr 正则表达式和条件执行来缩短它。

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

您也可以使用作为/ L

  setlocal enabledelayedexpansion 
do(
setint = 0 %% I
if exists * x!int:〜-2!c48 * goto script -a

goto script -b


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

解决方案

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

这篇关于我如何浓缩这个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆