批量循环最后一步

时间:2013-09-14 13:48:23

标签: loops for-loop batch-file

第一次发表海报(如果其他地方有答案,请找亲切,我找不到)。我相信还有其他20,000种现代方法可以实现以下目标,但我一直想要回答这个问题。

我要做的是运行循环,然后在循环结束时(完成),运行最后一步,与循环分开。我希望有人可以指出我的简单态度。

提前谢谢大家。

这是我的批次......

for /f "eol=#" %%i in (\\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push.txt) do call :sub "%%i"

:sub

if exist "\\%1\c$\vm\isovm\09132013.txt" goto good
goto bad
goto end

:good
echo %1     good    >> \\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt
goto end

:bad
echo %1     bad >> \\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt
goto end

:end


:done
\\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt

1 个答案:

答案 0 :(得分:0)

我不确定脚本末尾的行是什么,但你可以移动它在循环结束时执行它,如下所示:

for /f "eol=#" %%i in (\\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push.txt) do call :sub "%%i"

\\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt
goto end

:sub

if exist "\\%1\c$\vm\isovm\09132013.txt" goto good
goto bad

:good
echo %1     good    >> \\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt
goto end

:bad
echo %1     bad >> \\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt
goto end

:end

此外,我认为你可以像这样简化:

@echo off

for /f "eol=#" %%i in (\\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push.txt) do (
    if exist "\\%%i\c$\vm\isovm\09132013.txt" (
        echo %%i     good >> \\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt
    ) else (
        echo %%i     bad >> \\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt
    )
)

\\server\ops\!ReinsDeploy\WindowsXPMODE\isovm-push-confirm.txt

虽然自从我上次创建cmd.exe脚本以来已经有一段时间了,所以我希望它能够正常工作。