Exit in For loop - Windows Command Processor (CMD.EXE)

后端 未结 3 1540
半阙折子戏
半阙折子戏 2020-12-19 09:50

I am trying to find way to break / exit from FOR loop, if there are any error occured. Below is content of batch file.

@echo on

set myfile=D:\\sample.txt

F         


        
3条回答
  •  暖寄归人
    2020-12-19 10:19

    You don't need to call a label

    set USBDRIVE=SETLOCAL 
    set exit=ENABLEDELAYEDEXPANSION
    
    FOR %%D IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
      DIR %%D:\SOURCES\INSTALL.WIM > nul 2>&1 && call set USBDRIVE=%%D: && call set exit=1
      if defined exit goto :dd3
    )
    :dd3
    

提交回复
热议问题