批处理参数不正确

时间:2016-05-21 09:58:18

标签: batch-file tortoisesvn

用户输入参数未设置为checkoutdir变量。

@echo off
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
(for %%i in (%projects%) do (
            echo. Going to repository - %%i
            echo. Please provide checkoutdir name
            set /p checkoutdir= 
            echo. Checking out %SVN_REPO_URL%%%i from SVN...
            "%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%%checkoutdir%" /url:"%SVN_REPO_URL%%%i" /closeonend:2 
    )
)
echo.
echo. Operation complete.

问题: checkoutdir设置为项目目录名称 对于第一次迭代,它被设置为2016-05-18,导致E:\Svncheckout\21MAY2016\2016-05-18中的路径。对于第二次迭代,它设置为20160518,结果为E:\Svncheckout\21MAY2016\20160518

中的路径

2 个答案:

答案 0 :(得分:1)

此代码应该有效:

@echo off
echo.
echo. [ SVN Updater ]
setlocal EnableDelayedExpansion
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"
for %%i in (%projects%) do (
    echo. Going to repository - %%i
    echo. Please provide checkoutdir name
    set /p "checkoutdir=Directory name: "
    echo. Checking out %SVN_REPO_URL%%%i from SVN...
    "%SVN%\TortoiseProc.exe" /command:checkout /path:"%SOURCE%!checkoutdir!" /url:"%SVN_REPO_URL%%%i" /closeonend:2
)
echo.
echo. Operation complete.
endlocal

在启用延迟扩展后,必须使用感叹号而不是百分号来引用具有延迟扩展的变量。

打开命令提示符窗口,运行set /?并读取所有输出页面。

使用百分号引用的环境变量总是在解析命令行时分别使用( ... )定义的命令块进行扩展。

答案 1 :(得分:0)

有效。我必须将%checkoutdir%更改为!checkoutdir!