Batch program to add text to url

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tea
Posts: 2
Joined: 14 Oct 2019 11:58

Batch program to add text to url

#1 Post by tea » 14 Oct 2019 12:14

Hi Guys

Im not sure if Im in the right site or not.

Im looking for a batch program to automate a url link that changes.

I have this url format that does not change http://name.com:8080/username/password/30356

and need to have this format:http://name.com:8080/get.php?username=u ... d&type=gif

The 30356 is not needed.

Is there any kind of batch program that I can paste ----http://name.com:8080/username/password/30356 at a prompt and have an output of

http://name.com:8080/get.php?username=u ... d&type=gif

Thank you for your time

penpen
Expert
Posts: 1726
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch program to add text to url

#2 Post by penpen » 15 Oct 2019 04:25

This might help you:

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
:: uri encoded input of form:  http://name.com:8080/<username>/<password>/30356
set "input="
set /p "input="

:: variables of form
:: "%%~a" = "http:"
:: "%%~b" = "name.com:8080"
:: "%%~c" = "<username>"
:: "%%~d" = "<password>"
:: "%%~e" = "30356"
:: output of form http://name.com:8080/get.php?username=<username>&password=<password>&...&type=gif
set "output="
for /f "tokens=1-5 delims=/" %%a in ("!input!") do (
	set "output=%%~a//%%~b/get.php?username=%%~c&password=%%~d&...&type=gif"
)

echo(!output!

goto :eof
penpen

tea
Posts: 2
Joined: 14 Oct 2019 11:58

Re: Batch program to add text to url

#3 Post by tea » 15 Oct 2019 08:17

Thank you wow

You don't know how long I was trying just to make the batch just print a "&" symbol :roll: .....

The program works as advertised.

Is it possible to put the output to the clipboard?

Thank you again

Tea

penpen
Expert
Posts: 1726
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch program to add text to url

#4 Post by penpen » 15 Oct 2019 19:08

The tool clip.exe could be used for that:

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
:: uri encoded input of form:  http://name.com:8080/<username>/<password>/30356
set "input="
set /p "input="

:: variables of form
:: "%%~a" = "http:"
:: "%%~b" = "name.com:8080"
:: "%%~c" = "<username>"
:: "%%~d" = "<password>"
:: "%%~e" = "30356"
:: output of form http://name.com:8080/get.php?username=<username>&password=<password>&...&type=gif
set "output="
for /f "tokens=1-5 delims=/" %%a in ("!input!") do (
	set "output=%%~a//%%~b/get.php?username=%%~c&password=%%~d&...&type=gif"
	@(
		cmd /E:ON /V:ON /cecho(!output!
	)|clip
)


goto :eof
penpen

Post Reply