I have come up with this
echo.
echo. [ SVN Updater ]
setlocal enableDelayedExpansion
set SOURCE=E:\Svncheckout\
set SVN=C:\Program Files\TortoiseSVN\bin
set SVN_REPO_URL=https://SVNSERVERIP/svn/
set projects=project1/branches/hello1 project2/branches/hello2
set checkoutdir=project1 project2
echo.
SET PROJCOUNT=0
(for %%i in (%projects%) do (
echo. Checking out %SVN_REPO_URL%%%i from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%checkoutdir[0]%" /url:"%SVN_REPO_URL%%%i" /closeonend:2
PROJCOUNT+=1;
)
)
echo.
echo. Operation complete.
I would like to iterate the checkoutdir
list array with each directory name. I'm stuck here. I'm newbie to batch programming. Kindly help
Method 2 :
echo.
echo. [ SVN Updater ]
setlocal enableDelayedExpansion
set SOURCE=E:\Svncheckout\21MAY2016\
set SVN=C:\Program Files\TortoiseSVN\bin
set SVN_REPO_URL=https://192.168.1.35:8443/svn/
set projects=JPO/JPOMobile/branches/2016-05-18 JPO/JPOWEB/branches/20160518
set checkoutdir=JPOMobile JPOWEB
set /A CHECKOUTCOUNT=1
set /A PROJCOUNT=0
(for %%i in (%projects%) do (
SET /A "PROJCOUNT+=1"
(for %%a in (%checkoutdir%) do (
IF ("%PROJCOUNT%"=="%CHECKOUTCOUNT%") (
echo. Checking out %SVN_REPO_URL%%%i from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%%a" /url:"%SVN_REPO_URL%%%i" /closeonend:2
SET /A "CHECKOUTCOUNT+=1"
)
))
))
echo.
echo. Operation complete.
In the second method, it errors, set /A PROJCOUNT=0 in unexpected at this time.I think there is some problem in the for
loop
Here is my solution for this task:
@echo off
echo.
echo. [ SVN Updater ]
set "SOURCE=E:\Svncheckout\21MAY2016\"
set "SVN=%ProgramFiles%\TortoiseSVN\bin"
set "SVN_REPO_URL=https://192.168.1.35:8443/svn/"
set "projects=JPO/JPOMobile/branches/2016-05-18 JPO/JPOWEB/branches/20160518"
set "checkoutdir=JPOMobile JPOWEB"
set "ProjectCount=0"
for %%P in (%projects%) do call :CheckOut "%%P"
echo.
echo. Operation complete.
rem Exit batch processing to avoid a fall through to subroutine.
exit /B
:CheckOut
set /A ProjectCount+=1
for /F "tokens=%ProjectCount%" %%D in ("%checkoutdir%") do (
echo. Checking out %SVN_REPO_URL%%~1 from SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%%D" /url:"%SVN_REPO_URL%%~1" /closeonend:2
)
rem Exit this subroutine. It is also possible to use GOTO :EOF
exit /B
The first loop processes each project defined in environment variable projects
separated by a space. For each project the subroutine CheckOut
is called with the current project path as argument.
The subroutine CheckOut
first increments the project count variable which is the checkout directory string index with first string having index number 1.
The second loop in this subroutine interprets the list of directories in environment variable checkoutdir
now as a string instead of a list of strings because of using parameter /F
of FOR and enclosing the value of the environment variable in double quotes.
To get the Nth checkout directory from the string with the checkout directories separated by spaces, the tokens=x
syntax is used whereby x
is the current value of project count variable.
The checkout is done with the Nth checkout directory and the current project referenced with %~1
as being passed to the subroutine as first argument.
For details on using subroutines and referencing parameters run in a command prompt window call /?
and read all output help pages.
A subroutine as used here is like having another batch file embedded in current batch file.
NOTE: There is a limit of 31 tokens. ProjectCount
should therefore not exceed the value 31.