针对URL列表打开一批文件 [英] Batch file for opening one of a list of URLs
问题描述
我的网站列表。我想一个批处理文件将在列表中打开只有第一个网站时,我执行了第一次的bat文件,当我执行了第二次的批处理文件,它会打开只有在列表中的第二个网站,当我执行它第三时候就会在列表中只开三分之一的网站等。
有人建议我以下解决方法:
关闭@echo&放大器; SETLOCAL EnableDELAYedExpansion如果不存在%TEMP%\\ runnum回声1 GT; %TEMP%\\ runnum
设置/ p R =<%TEMP%\\ runnum
设定N =FOR / F令牌= * delims =%%一中(MYFILE)做(
集/ A N + = 1
如果!N! EQU! - [R!呼应火狐%%一个布拉布拉
)
集/ A R + = 1
呼应R>! %TEMP%\\ runnum
但我不知道他是什么意思通过(MYFILE)
和布拉布拉
,因为我不知道关于脚本或编程任何东西。
有人可以帮我。假设我的网站名单是:
http://meebo.com
http://yahoo.com
http://google.com
http://orkut.com
http://facebook.com
http://msn.com
http://cnn.com
http://myspace.com
http://twitter.com
这其实并不难。 MYFILE
成为您在其中存储你的URL列表的文件名和布拉布拉
是简单地传递到Firefox附加参数。
虽然有几个点的一个可以提高
-
依托Firefox是不是最好的事情。我建议使用
启动%%一个
来代替,因为这滋生的默认浏览器,而不是硬编码一个特定的。
-
更是达到了你的文件的网站数量时,您的批次将失败,可能只是产生一个新的Firefox窗口。下面我创建了消除这两个问题批次:
关闭@echo
SETLOCAL ENABLEEXTENSIONS
REM取第一个URL
设置/ p URL =< LIST.TXT
REM打开该网址,浏览器
启动%URL%
REM从文件的前面删除网址...
更+1 LIST.TXT | FINDSTR / R / V^ $> tmp_list.txt
REM ......并把它进行到底
回声%URL%方式>> tmp_list.txt
德尔LIST.TXT
仁tmp_list.txt LIST.TXT
ENDLOCAL
该版本不依赖于特定的浏览器。它将简单地滚动文件本身,通过去除第一URL和它再次粘到端。所以只要你有你的网址文件(即 LIST.TXT
在这种情况下),它是pretty多自成体系。 code可在我的 SVN仓库为好。
ETA:解释那批的某些部分:
设置/对URL =< LIST.TXT
这将在 LIST.TXT
第一线存储在环境变量网址
。通常设置/ P
提示用户输入。通过将文件重定向到这个命令,我们基本上是pretending文件的内容是用户的输入。
启动%URL%
将打开一个网页,文件,文件夹,等等。 启动
做正确的事™自动的(主要是:))。如果我们给它一个URL会打开默认的浏览器吧,这是我们使用这里。周围的URL的两个引号将确保像&放字符;
的URL会正确地传递给浏览器,他们有一个特殊的意义,否则。两个引号直接下启动
是必要使用带有引号时启动
可言,很遗憾。否则启动
会间preT URL作为窗口标题这可能不正是我们想在这里新的控制台窗口。
更多+1 LIST.TXT | FINDSTR / R / V^ $> tmp_list.txt
这几个部分组成。首先,更多+1
将导致文件输出,跳过第一道防线。正如我们记得,第一行是我们想要打开(应该已经发生)的第一个URL。我们想要做的是从文件开始删除URL,并把它进行到底。所以第一步是从一开始,这就是更多+1 LIST.TXT
在这里所做的将其删除。
然后,无论更多
版画被传递到 FINDSTR
。 FINDSTR
是一个方便的工具来搜索字符串一般。我们在这里做什么是启用 / R
常规EX pressions(有点程序员的梦想的工具来处理文本 - 如果他们可以,他们会写在正规完整的程序前pressions,但我离题)。然后 / V
引起 FINDSTR
打印每行的不的匹配我们以后指定。我们在这里寻找的模式是^ $
这只是REG-EX为空行说话。
因此,在一条线,我们从文件中删除的第一行的和的删除任何空行。 (这些空行会导致该批处理文件做奇怪的事情。记住,启动
做的大多的正确的事情呢?这是一个这样的案例。一个在文件中的空行会导致资源管理器窗口与当前文件夹出现,而不是下一个网页浏览器。因此,我们需要摆脱那些。)
最后,我们写的一切这些命令打印到一个新的文件,名为 tmp_list.txt
。别担心,它不会左右徘徊太久。
回声%URL%方式>> tmp_list.txt
这将追加URL刚刚打开我们的临时名单。没什么特别的事情在这里。
德尔LIST.TXT
仁tmp_list.txt LIST.TXT
最后,我们删除旧列表并重新命名暂时的旧名称。
ETA:由于您请求一个版本,可以一气呵成打开多个页面,接下来是一个快速和肮脏的黑客使这一点:
关闭@echo
SETLOCAL ENABLEEXTENSIONS
设置NUM = 3
对/ L %%我在(1,1,%NUM%)做致电:启动
ENDLOCAL
GOTO:EOF:开始
设置/ p URL =< LIST.TXT
启动%URL%
更+1 LIST.TXT | FINDSTR / R / V^ $> tmp_list.txt
回声%URL%方式>> tmp_list.txt
德尔LIST.TXT
仁tmp_list.txt LIST.TXT
GOTO:EOF
没有冗长的解释,这个时候,虽然。这篇文章已经够长了。您可以控制的,通过改变接近文件顶部的 NUM
变量打开的页面数量。
设置NUM = 5
将导致五页打开而不是三个。
I have a list of websites. I want a batch file which will open only first website in the list when i execute the bat file for first time and when i execute the batch file for second time it will open only the second website in the list and when i execute it for third time it will open only third website in the list and so on. Someone suggested me following solution:
@echo off & setLocal EnableDELAYedExpansion
if not exist %TEMP%\runnum echo 1> %TEMP%\runnum
set /p R=<%TEMP%\runnum
set N=
for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
if !N! equ !R! echo firefox %%a blabla
)
set /a R+=1
echo !R!> %TEMP%\runnum
But I don't know what he meant by (myfile)
and blabla
because i don't know anything about scripting or programming.
Can someone help me further. Assuming my list of websites are:
http://meebo.com http://yahoo.com http://google.com http://orkut.com http://facebook.com http://msn.com http://cnn.com http://myspace.com http://twitter.com
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.
这篇关于针对URL列表打开一批文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!