终于实现了for循环嵌套,特此记录
@echo off
@setlocal enabledelayedexpansion
:loop
set P4PORT=127.0.0.1:1666
set P4USER=game_svr
set P4CLIENT=win_stable
set P4ROOT=d:\p4
set DIFFTOOL="C:\Program Files (x86)\Beyond Compare\BCompare.exe"
set /P remaincsv=csv name: %=%
set /P branchlist=branch: %=%
:split
for /f "tokens=1* delims= " %%a in ("%remaincsv%") do (
set csvname=%%a
set remaincsv=%%b
set remainbranch=%branchlist%
:subsplit
for /f "tokens=1* delims= " %%c in ("%remainbranch%") do (
set branchname=%%c
cd %P4ROOT%\%%c\client\SGameClient\res\table
p4 diff -f %csvname% | findstr "^> " > d:\%%c_%csvname%.diff
cd %P4ROOT%\stable\client\SGameClient\res\table
p4 diff -f %csvname% | findstr "^> " > d:\stable_%csvname%.diff
%DIFFTOOL% d:\%%c_%csvname%.diff d:\stable_%csvname%.diff
set remainbranch=%%d
)
if defined remainbranch goto :subsplit
)
if defined remaincsv goto :split
goto :loop
pause
网上看了很多教程,很少讲分割字符串然后遍历所有列的,现在我实现了这种逻辑。这里需要注意一下,第二层循环的总列表需要在第一层用一个变量承载,不然在第一次二层循环完成之后,这个队列就会清空。