Batch file 如何在批处理中退出for/f循环?

Batch file 如何在批处理中退出for/f循环?,batch-file,batch-processing,Batch File,Batch Processing,我有一个关于我正在编写的批处理文件的问题 如何定义for/f循环以仅执行脚本的一部分而不是整个脚本 在下面的脚本中,我想 我想我需要使用一个调用方法,因为另一个问题是反弹 感谢您的帮助: @echo off setlocal enabledelayedexpansion WMIC LOGICALDISK where drivetype=3 get caption>%~n0.tmp for /f "tokens=1-3 skip=1" %%a in ('type "%~n

我有一个关于我正在编写的批处理文件的问题

如何定义for/f循环以仅执行脚本的一部分而不是整个脚本

在下面的脚本中,我想

我想我需要使用一个调用方法,因为另一个问题是反弹

感谢您的帮助:

    @echo off
  setlocal enabledelayedexpansion
  WMIC LOGICALDISK where drivetype=3 get caption>%~n0.tmp
  for /f "tokens=1-3 skip=1" %%a in ('type "%~n0.tmp"') do call :displayinfo %%a
del "%~n0.tmp"
goto :eof

:displayinfo
set drive=%1
echo Le drive est %drive%
echo lancement du DIR
REM call dir /A HS /s /b %drive%\ >> d:\Dir_ALL.txt
echo Fin du DIR

:step2
echo this is the step2, to be executed when the for /F loop is over.
echo blablalblablalballbabal

:step_End
echo Ths is the end
@pause

你需要做两个改变

将for行下方两行的goto:eof更改为goto:step2。 添加goto:EOF作为:displayinfo方法的最后一行。这将导致该方法返回for循环。 应该是这样的

@echo off
setlocal enabledelayedexpansion
WMIC LOGICALDISK where drivetype=3 get caption>%~n0.tmp
for /f "tokens=1-3 skip=1" %%a in ('type "%~n0.tmp"') do call :displayinfo %%a
del "%~n0.tmp"
goto :step2

:displayinfo
set drive=%1
echo Le drive est %drive%
echo lancement du DIR
REM call dir /A HS /s /b %drive%\ >> d:\Dir_ALL.txt
echo Fin du DIR
goto :EOF

:step2
echo this is the step2, to be executed when the for /F loop is over.
echo blablalblablalballbabal

:step_End
echo Ths is the end
@pause

你需要做两个改变

将for行下方两行的goto:eof更改为goto:step2。 添加goto:EOF作为:displayinfo方法的最后一行。这将导致该方法返回for循环。 应该是这样的

@echo off
setlocal enabledelayedexpansion
WMIC LOGICALDISK where drivetype=3 get caption>%~n0.tmp
for /f "tokens=1-3 skip=1" %%a in ('type "%~n0.tmp"') do call :displayinfo %%a
del "%~n0.tmp"
goto :step2

:displayinfo
set drive=%1
echo Le drive est %drive%
echo lancement du DIR
REM call dir /A HS /s /b %drive%\ >> d:\Dir_ALL.txt
echo Fin du DIR
goto :EOF

:step2
echo this is the step2, to be executed when the for /F loop is over.
echo blablalblablalballbabal

:step_End
echo Ths is the end
@pause

通常的方法是使用goto:label,它打破了上下文,但你想退出什么循环。谢谢。实际上,我希望我的脚本使用WMIC列出每个驱动器,然后执行:displayinfo标签。所以我想让它执行一个DIR/ahs。。。在找到的每个驱动器上。然后当这个循环结束时,我想进入步骤2,等等。。所以不再在循环中。通常的方法是使用goto:label,它打破了上下文,但你想退出什么循环。谢谢。实际上,我希望我的脚本使用WMIC列出每个驱动器,然后执行:displayinfo标签。所以我想让它执行一个DIR/ahs。。。在找到的每个驱动器上。然后当这个循环结束时,我想进入步骤2,等等。。所以不再循环。谢谢,我想我没有正确理解EOF的方法。谢谢,我想我没有正确理解EOF的方法。