我为我的项目编写了批处理文件。我喜欢浏览我的svn-http-address,所以我可以知道我是在分支机构还是在主干机上工作。而且分支名称也很有用。
我将搜索的路径如下:
我试过" for"和"%变量:StrToFind = NewStr%"突击队。但我最终遇到的问题是" /",":"字符。
任何想法如何解决这个问题。
由于
答案 0 :(得分:1)
我试过“for”和“%variable:StrToFind = NewStr%”突击队。
@ECHO OFF >NUL
SETLOCAL enableextensions
set "_addr1=https://aaa.com/bbb/ccc/ddd/trunk/"
set "_addr2=%_addr1:trunk=branches/thebranchname%"
set "_adold=trunk/"
set "_adnew=branches/thebranchname"
call set "_addr3=%%_addr1:%_adold%=%_adnew%%%"
rem from cmd: (note %s vs. %%s) call set "_addr3=%_addr1:%_adold%=%_adnew%%"
rem with enabledelayedexpansion call set "_addr3=!_addr1:%_adold%=%_adnew%!"
set _
<强>输出强>:
==>set _ad
Environment variable _ad not defined
==>D:\bat\SO\31209302.bat
_addr1=https://aaa.com/bbb/ccc/ddd/trunk/
_addr2=https://aaa.com/bbb/ccc/ddd/branches/thebranchname/
_addr3=https://aaa.com/bbb/ccc/ddd/branches/thebranchname
_adnew=branches/thebranchname
_adold=trunk/
==>
答案 1 :(得分:1)
非常简单:
@ECHO OFF
set "adress=https://aaa.com/bbb/ccc/ddd/trunk/"
call :Where %adress%
set "adress=https://aaa.com/bbb/ccc/ddd/branches/thebranchname"
call :Where %adress%
set "adress=https://aaa.com/bbb/ccc/ddd/neither/thebranchname"
call :Where %adress%
goto :eof
:Where
echo address: %adress%
echo %1|find /i "/trunk">nul && (echo I'm in Trunk & goto :eof)
echo %1|find /i "/branches">nul || (echo neither trunk nor branches & goto :eof)
set "branchname=%adress:*branches/=%"
echo I'm working for %branchname%
goto :eof