2015-07-03 126 views
0

我为我的项目编写了一个批处理文件。我喜欢浏览我的svn-http地址,因此我可以了解我是否在分支机构或中继线上工作。而且分支名称也很有趣。CMD解析http地址

,我将在外表搜索等的路径:

我试图与 “for” 和 “%变量:StrToFind =%中newstr” 突击。但是我最终遇到了“/”,“:”字符的问题。

任何想法,我可以如何解决这个问题。

由于

+0

如何区分? “'trunk”“与”'branches'“?那些固定的字符串? – Stephan

+0

“主干”和“分支”是固定字符串,可以解析它们。 – Matt

回答

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 
+0

感谢您的解决方案。完美的作品。 – Matt

1

我试图与 “for” 和 “%变量: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/ 

==>