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.
精彩评论