Windows Batch: open multiple url tabs based on txt file

Hello experts,

I have the following bat file which allows me to open automatically multiple tabs.
I would like to add the following requirement:

@echo off

SET BROWSER=chrome.exe
SET WAIT_TIME=2
START %BROWSER% -new-tab "url"
START %BROWSER% -new-tab "url2”"

Open in new window


Instead of reporting url I would like to loop a url.txt which contains the various urls.
Error checking:
If url.txt file doesn’t exists
LVL 1
Luis DiazIT consultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Give this a try:

@echo off

SET BROWSER=chrome.exe
SET WAIT_TIME=2
SET URL_LIST=url.txt

IF NOT EXIST "%URL_LIST%" (
    ECHO *ERROR* Missing URL list file "%URL_LIST%"
    EXIT /B
)

FOR /F "tokens=*" %%U in ('type "%URL_LIST%"') do (
    START %BROWSER% -new-tab "%%~U"
)

Open in new window


»bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Luis DiazIT consultantAuthor Commented:
Thank you Bill, Possible to report URL_LIST variable with an specific path such as "C:\Test"?
Bill PrewIT / Software Engineering ConsultantCommented:
You can use any valid file name.


»bp
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
That is you just add the path to the variable:
SET URL_LIST=C:\Test\url.txt

Open in new window

Luis DiazIT consultantAuthor Commented:
Noted. Unable to test it right now. I will test it as soon as I can.
Luis DiazIT consultantAuthor Commented:
Tested and it works! Thank you very much for your help.
I have a question, if I want to add a comment in url.txt file in front of url  which string or character should I use.

Example
http://url "comment"
http://url2 "comment2

Open in new window


Thank you again for your help.
Bill PrewIT / Software Engineering ConsultantCommented:
The way it is set up currently you can't.  It takes the whole line as the URL.

If you wanted you could select a character as the comment start and ignore anything after that (space, pipe, semi colon, etc).  Then a small change to the FOR /F loop would be needed to accommodate that.


»bp
Luis DiazIT consultantAuthor Commented:
Ok, In that cas what I will do is to comment directly through rem in the bat file. Thank you again for your help. Bill!
Bill PrewIT / Software Engineering ConsultantCommented:
Welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.