2015-07-03 54 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/ 

==>