This is actually not that hard. myfile
becomes the file name in which you store your list of URLs and blabla
are simply additional parameters passed to Firefox.
Though there are a few points one could improve:
Relying on Firefox isn't the best thing. I'd suggest using
start "" "%%a"
instead, since that spawns the default browser instead of hardcoding a specific one.
Your batch will fail when the number of websites in your file is reached and probably just spawn a new Firefox window. Below I have created a batch which eliminates both problems:
@echo off
setlocal enableextensions
rem fetch the first URL
set /p URL=<list.txt
rem Open the browser with that URL
start "" "%URL%"
rem Remove the URL from the front of the file ...
more +1 list.txt | findstr /r /v "^$" > tmp_list.txt
rem ... and put it to the end
echo.%URL%>>tmp_list.txt
del list.txt
ren tmp_list.txt list.txt
endlocal
This version doesn't rely on a specific browser. It will simply roll the file itself, by removing the first URL and sticking it to the end again. So as long as you have your URL file (which is list.txt
in this case) it's pretty much self-contained. Code may be found in my SVN repository as well.
ETA: Explaining some parts of that batch:
set /p URL=<list.txt
This will the first line in list.txt
to be stored in the environment variable URL
. Usually set /p
prompts for user input. By redirecting the file into this command we are basically pretending the file's contents were user input.
start "" "%URL%"
will open a web page, document, folder, whatever. start
does The Right Thing™ automagically (mostly :)). If we give it a URL it will open the default browser with it, which is what we're using here. The two quotation marks around the URL will ensure that characters like &
in URLs will get passed correctly to the browser, they have a special meaning otherwise. The two quotation marks directly following start
are necessary when using quotation marks with start
at all, unfortunately. Otherwise start
would interpret the URL as the window title for a new console window which may not be exactly what we want here.
more +1 list.txt | findstr /r /v "^$" > tmp_list.txt
This has several parts. First of all more +1
causes a file to be output, skipping the first line. As we remember, the first line is the first URL we wanted to open (which should have happened already). What we want to do is to remove that URL from the start of the file and put it to the end. So the first step is to remove it from the start, which is what more +1 list.txt
does here.
Then, whatever more
prints gets passed into findstr
. findstr
is a handy utility to search for strings usually. What we do here is enable regular expressions with /r
(sort of programmers' dream tool for handling text – if they could, they would write complete programs in regular expressions, but I digress). Then /v
causes findstr
to print every line not matching what we specify after that. The pattern we are searching for here is "^$"
which is just reg-ex speak for "empty line".
So in one line we remove the first line from the file and remove any empty lines from it. (Those empty lines would cause the batch file to do weird things. Remember that start
does mostly the right thing? This is one such case. An empty line in your file would cause an Explorer window with your current folder to appear, instead of a browser with the next web page. So we need to get rid of those.)
Finally we write everything those commands print into a new file, called tmp_list.txt
. Don't worry, it won't linger around for too long.
echo.%URL%>>tmp_list.txt
This appends the URL just opened to our temporary list. Nothing fancy going on here.
del list.txt
ren tmp_list.txt list.txt
Finally we delete the old list and rename the temporary one to the old name again.
ETA: Since you requested a version which can open multiple pages in one go, what follows is a quick and dirty hack which enables just that:
@echo off
setlocal enableextensions
set num=3
for /l %%i in (1,1,%num%) do call :start
endlocal
goto :eof
:start
set /p URL=<list.txt
start "" "%URL%"
more +1 list.txt | findstr /r /v "^$" > tmp_list.txt
echo.%URL%>>tmp_list.txt
del list.txt
ren tmp_list.txt list.txt
goto :eof
No lengthy explanation this time, though. This post is already long enough. You can control the number of pages opening by changing the num
variable near the top of the file.
set num=5
will cause five pages to open instead of three.