开发者

MS-DOS batch script: substring from url

I have an othe开发者_JAVA百科r question.

I have an url like this

@SET var1="http://www.domain.com/dir1/dir2/dir3/dir4/dir5/file.txt".

In this url I need to get "http://www.domain.com/dir1/dir2/dir3/dir4/dir5/" path.

Thanks.


How about this?

@echo off
setlocal enabledelayedexpansion

set var1="http://www.domain.com/dir1/dir2/dir3/dir4/dir5/file.txt"

set var2=%var1%

:loop
if "!var2:~-2,1!"=="/" goto endloop
set var2="%var2:~1,-2%"
goto loop

:endloop
echo.%var2%

It removes characters from the end of the path until / is reached.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜