I have a text file with lots of links-each line has a link (i.e the separator is '\n'). i want to write a script so that each link opens in a different tab in Firefox or Internet explorer. How can I do this? I'm on Windows 7
-
Question could be clarified a little bit: do you want to keep the list in a plain text format so that you can easily edit it, or do you want to just convert it as-is to a script? – hallvors Oct 04 '10 at 04:22
-
@hallvors:yes, the list is in plain text format only – iceman Oct 04 '10 at 13:39
-
so you would rather not convert it to a batch file per instructions below? :) – hallvors Oct 05 '10 at 02:45
4 Answers
The solution that worked for me is:
set "fileList="
FOR /F "usebackq delims=," %%i IN ("C:\Documents and Settings\xwell\Desktop\urls.txt") DO (
start %%i
)
Four changes I made:
- I set the delimiter to a comma - delims=,
- Put a comma between each URL in my text file
- And put the for loop function in brackets
- Changed the start function. This uses the default browser, though you could specify it as per the above example
So, the text file urls.txt looks like:
http://www.rte.ie,
http://www.python.org,
http://www.bbc.co.uk,
http://www.google.com

- 71
- 3
Create a text file called whatever.bat and put it on your desktop. edit the file and enter:
set "fileList="
FOR /F "usebackq delims==" %%i IN ("C:\Documents and Settings\mdevine\Desktop\urls.txt") DO call set "fileList=%%fileList%% %%i"
start firefox %fileList%
close and save
double click on it
Note: C:\Documents and Settings\mdevine\Desktop\urls.txt is a text file that contains the following:
http://www.rte.ie
http://www.python.org
http://www.bbc.co.uk
http://www.google.com

- 2,724
- 4
- 37
- 58
@iceman, @amadain:
refining @amadains solution: the "line continuation character" in batch files is ^, so iceman should change his text files accordingly (add a ^ at the end of each line) and put "start firefox ^" at the beginning of the file . Don't know max length of command line string, though.
If anyone is looking for how to do this in Chrome, here is the solution :
@echo off
set URL1= https://www.google.com
set URL2= https://www.youtube.com
set URL3= https://stackoverflow.com
start chrome --new-window "%URL1%" "%URL2%" "%URL3%"
Save this code as batch file and just double click.
Note that there is no space before the = sign It wasn't working for me when i tried with space

- 686
- 2
- 13
- 40