簡體   English   中英

批處理腳本“繼續”循環?

[英]batch script “continue” in loop?

do ( ) 不適用於我在線獲取的代碼,因此我使用 do :processline。 問題是“繼續”; 想要進入下一次迭代時不起作用。 問題在於它為每次迭代執行 :eof 而不是 post loop ......如何避免這種情況? 謝謝

SET NGCSV=UserList3Col.csv
SET NGCSVT1=UserList3Col.csv.temp1
SET NGCSVT2=UserList3Col.csv.temp2
SET NGFINAL=UserListFinal.csv
del %NGFINAL%
set /a c=0
for /f "tokens=1" %%i in (groupList.txt) do call :processline %%i
goto :eof

:processline 
SET GROUP=%*
setlocal EnableDelayedExpansion
net group /domain "GG-%GROUP%" > %NGCSV%
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
REM Now strip out the crap
REM ...make a temporary copy
COPY %NGCSV% %NGCSVT2%
REM ...strip off the crap using alternating temp files
findstr /B /L /V /C:"The request" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"Group name" %NGCSVT1% > %NGCSVT2%
findstr /B /L /V /C:"Comment" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"Members" %NGCSVT1% > %NGCSVT2%
findstr /B /L /V /C:"-----" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"The command" %NGCSVT1% > %NGCSVT2%
REM ...make the last temporary copy the final copy and clean up
COPY %NGCSVT2% %NGCSV%
DEL %NGCSVT1%
DEL %NGCSVT2%
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
REM ...Column 1
for /F "tokens=1" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
REM ...Column 2
for /F "tokens=2" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
REM ...Column 3
for /F "tokens=3" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
del %NGCSV%
continue; rem Doesn't work

:eof
set /a c=c+1
echo %c%

continue; 不是內部或外部命令。

EOF是 CMD 中的內部標簽,不需要包含。

測試這個:

SET NGCSV=UserList3Col.csv
SET NGCSVT1=UserList3Col.csv.temp1
SET NGCSVT2=UserList3Col.csv.temp2
SET NGFINAL=UserListFinal.csv
del %NGFINAL%
set /a c=0
for /f "tokens=1" %%i in (groupList.txt) do call :processline %%i
goto :continue

:processline 
set /a c=c+1
echo %c%
SET GROUP=%*
setlocal EnableDelayedExpansion
net group /domain "GG-%GROUP%" > %NGCSV%
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
REM Now strip out the crap
REM ...make a temporary copy
COPY %NGCSV% %NGCSVT2%
REM ...strip off the crap using alternating temp files
findstr /B /L /V /C:"The request" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"Group name" %NGCSVT1% > %NGCSVT2%
findstr /B /L /V /C:"Comment" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"Members" %NGCSVT1% > %NGCSVT2%
findstr /B /L /V /C:"-----" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"The command" %NGCSVT1% > %NGCSVT2%
REM ...make the last temporary copy the final copy and clean up
COPY %NGCSVT2% %NGCSV%
DEL %NGCSVT1%
DEL %NGCSVT2%
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
REM ...Column 1
for /F "tokens=1" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
REM ...Column 2
for /F "tokens=2" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
REM ...Column 3
for /F "tokens=3" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
del %NGCSV%
goto :EOF
:continue
echo this is reached after the entire file is parsed
pause

這段代碼也應該以相同的方式工作,除了! 當使用延遲擴展時,字符會變成毒字符。

@echo off
setlocal enabledelayedexpansion
SET NGCSV=UserList3Col.csv
SET NGCSVT1=UserList3Col.csv.temp1
SET NGCSVT2=UserList3Col.csv.temp2
SET NGFINAL=UserListFinal.csv
del %NGFINAL% 2>nul
del %NGCSV%   2>nul
set /a c=0
for /f "tokens=1" %%i in (groupList.txt) do (
set /a c=c+1
echo !c!
net group /domain "GG-%%i" |findstr /B /L /V /i /C:"The request" /C:"Group name" /C:"Comment" /C:"Members" /C:"-----" /C:"The command" > %NGCSV%
REM ...Column 1
for /F "tokens=1" %%A in (%NGCSV%) do >>%NGFINAL% echo %%i,%%A
REM ...Column 2
for /F "tokens=2" %%A in (%NGCSV%) do >>%NGFINAL% echo %%i,%%A
REM ...Column 3
for /F "tokens=3" %%A in (%NGCSV%) do >>%NGFINAL% echo %%i,%%A
del %NGCSV%
)
pause

我用這個來繼續循環(注意:next標簽必須有一些代碼,我使用echo smth > nul ):

for /f "eol= tokens=*" %%a in (settings.ini) do ( 
  set line=%%a    

  if "%line%"=="!line:[Server]=!" (
    echo ***[Server] section found
    goto :next
  ) 

  :next
  echo continue this loop > null
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM