Computing.Net > Forums > Programming > Need A batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need A batch file

Reply to Message Icon

Name: dhiraj06
Date: August 27, 2009 at 04:49:24 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: August 27, 2009 at 07:00:37 Pacific
Reply:

Didn't we go through this a couple days ago?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: dhiraj06
Date: August 27, 2009 at 07:39:12 Pacific
Reply:

Hi Mechanix2Go,

I did tried with following answer:

@Echo off
Set /a TimesRun=%TimesRun%+1

If %TimesRun% == 1 "C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab

http://google.com
If %TimesRun% == 2 "C:\Program Files\Mozilla Firefox\firefox" -new-tab http://yahoo.com
If %TimesRun% == 3 "C:\Program Files\Mozilla Firefox\firefox" -new-tab http://cnn.com
If %TimesRun% gtr 4 Set /a TimesRun=0

But everytime i executed this .bat file I ended with a firefox window with www.google .com tab at each and every execution.
Can you explain me what is wrong here.


0

Response Number 3
Name: dhiraj06
Date: August 27, 2009 at 08:25:28 Pacific
Reply:

sorry, retyping again because i forget .exe suffix with firefox, nevertheless i am getting same result with following .bat script.
Hi Mechanix2Go,

I did tried with following answer:

@Echo off
Set /a TimesRun=%TimesRun%+1

If %TimesRun% == 1 "C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab

http://google.com
If %TimesRun% == 2 "C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab http://yahoo.com
If %TimesRun% == 3 "C:\Program Files\Mozilla Firefox\firefox.exe" -new-tab http://cnn.com
If %TimesRun% gtr 4 Set /a TimesRun=0

But everytime i executed this .bat file I ended with a firefox window with www.google .com tab at each and every execution.
Can you explain me what is wrong here.


0

Response Number 4
Name: Mechanix2Go
Date: August 27, 2009 at 08:44:59 Pacific
Reply:

For a bat to know where it left off, not much choice but to write a file.

===========================
@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


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: dhiraj06
Date: August 27, 2009 at 14:14:30 Pacific
Reply:

thanks for quick response, Mechanix2go.
But I can not put it to be useful for my purpose myself alone because i don't know anything about batch or for that matter any sort of programming unless someone feeds me with silver spoon.
So please do provide me a step by step guide telling me how to proceed from scratch to finish.
make it for me a copy and paste work.
your effort will be duly appreciated.
(As for the batch script i provided to make a solution of my problem, was also a copy and paste work with the script provided to me by a user named ace_omega at this forum.)

regards.


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: August 28, 2009 at 04:56:16 Pacific
Reply:

The only thing you need to change is the line below to make firefox do what you want:

if !N! equ !R! echo firefox %%a blabla


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: dhiraj06
Date: August 28, 2009 at 05:55:44 Pacific
Reply:

Thanks,Mechanix2Go
But I am confused about myfile in the line below:

or /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1

Which myfile do you referring here. What I did I put following text in a notepad, named it sequential execution.bat and then double clicked the same bat file but nothing happened:

@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 "c:\program files\mozilla firefox\firefox.exe" %%a -new-tab http://google.com -new-tab http://yahoo.com -new-tab http://cnn.com
)
set /a R+=1
echo !R!> %TEMP%\runnum

Please have patience with me and be little bit more elaborative. It will be a great help if you provide me a scratch to finish text of workable script supposing I have list of 10 websites like http://google.com, http://yahoo.com and so on.

Regards.



0

Response Number 8
Name: dhiraj06
Date: August 28, 2009 at 16:44:20 Pacific
Reply:

Please help.


0

Response Number 9
Name: dhiraj06
Date: August 29, 2009 at 07:52:32 Pacific
Reply:

Thanks to Mechanix2go,
Following suggestion on another site worked for me.

@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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Need A batch file

need a batch file www.computing.net/answers/programming/need-a-batch-file/13744.html

Editing a Text File With a Batch www.computing.net/answers/programming/editing-a-text-file-with-a-batch/14889.html

Help coding a batch file www.computing.net/answers/programming/help-coding-a-batch-file/17125.html