I have such a situation. I have a list of urls in a file.
SET str1="http://www.domain.com/dir1/dir2/dir3/dir4/dir5/file1.txt"
In the line above, http://www.domain.com/dir1/dir2/dir3 constant in all URLs. I need to extract the rest of the path in each url.
http://www.domain.com/dir1/dir2/dir3
I mean, I need to get the final line from the above url /dir4/dir5/file1.txt
/dir4/dir5/file1.txt
thanks
You need the notation %var:~start,end% . For example, if you run this:
%var:~start,end%
@SET str1="http://www.domain.com/dir1/dir2/dir3/dir4/dir5/file1.txt" @ECHO %str1:~37,-1%
This opens /dir4/dir5/file1.txt .
Alternatively, you can use the syntax %variable:str_to_delete=% to remove the character string from this variable. Thus, you do not need to rely on the position of the character within the string.
%variable:str_to_delete=%
Code example:
@echo off set str1="http://www.domain.com/dir1/dir2/dir3/dir4/dir5/file1.txt" :: remove the common part of the path set str2=%str1:http://www.domain.com/dir1/dir2/dir3=% :: remove the quotes set str2=%str2:"=% echo.%str2%
Conclusion:
Source: https://habr.com/ru/post/890031/More articles:.NET DateTime to time_t in seconds - c ++How to get lost id element in jQuery event - jqueryScalaTest in Java Eclipse project - javaWhy does a double / numeric value in a matrix return an incorrect answer using% in% a range? - rHow to get a clear image after low-frequency image suppression? - image-processingamortized cost splay tree: cost + P (tf) - P (ti) ≤ 3 (rankf (x) - ranki (x)) explanation - algorithmSaving a session using HttpWebRequest - c #How to create a virtual host from Apache.htaccess? - url-rewriting"Input file not specified" Error in WordPress - wordpressDatabase cleanup clears all tables even when used: except for the option - ruby-on-railsAll Articles