开发者

MS-DOS batch script: substring from url

开发者 https://www.devze.com 2023-03-11 23:00 出处:网络
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\".

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

精彩评论

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