Question:
Batch file that cycles through a list daily?
Staley
2009-03-02 04:34:54 UTC
I am looking to create a batch file that cycles through a list daily. Every day it would display the next item in the list. The list will be in a notepad document.

For example on the 1st it would display A, on the 2nd it would display B, on the 3rd it would display C, etc...

I am trying to create this for my wife so when she logs into the computer it would echo a new, and different message to her every day.
Five answers:
Josh H
2009-03-02 09:22:41 UTC
Batch scripting is not the ideal way to do this, but it is by no means insurmountable. You could use the following code:



@echo off

set sz_mymsg=

for /f %%i in (iter.txt) do set int_iter=%%i

for /f "tokens=1*" %%a in (list.txt) do (

if "%%a"=="%int_iter%" (

set sz_mymsg=%%b

goto SHOW_MSG ) )

:SHOW_MSG

if "%sz_mymsg%"=="" goto eof

echo MsgBox "%sz_mymsg%", 0, "Daily Message" >mymsg.vbs

call mymsg.vbs

del mymsg.vbs

set /a int_iter+=1

echo %int_iter% >iter.txt

:eof





Make sure that the line that starts with "echo MsgBox" ends with ">mymsg.vbs" I think that Y!A is going to wrap it onto the next line, which won't work.



This will work if list.txt is a file with the things you want to say formatted like this:



1 The first message to display

2 The next message



etc., etc. You will need to initialize your iterator by making a file iter.txt that contains the number one and nothing else.



Now, to get one message a day, just use the windows task scheduler and set it up to run your batch program.



I know that this is a crude way to do the job, but when people say that it can't be done, or that it is really hard, it stirs up this strange desire to prove them wrong. I guess that in the end I still ended up using VBS, but you could have just as easily displayed the message in a console window if you wanted.



Hope this helps.



~EDIT~

Just add these two lines at the top of the code:



for /f "tokens=*" %%i in (lastdate.txt) do if "%%i"=="%date%" goto eof

echo %date%>lastdate.txt



If you wanted to, you could easily combine your iter.txt and lastdate.txt into one file, but this gives you the idea. Like I said, there are way more efficient ways to do this, but this will work if you have your heart set on using a batch file.
anonymous
2009-03-02 04:51:01 UTC
You are going to have a difficult time trying to do that with a batch file. I would strongly suggest VBScript as it will run anywhere an you have a lot more at your disposal to do what you want, including opening a text file, determining day of the week, etc.



It is not a difficult language to learn either.



There is a really good learning resource here http://www.microsoft.com/technet/scriptcenter/default.mspx.



Hope that is useful
braggcolin
2009-03-02 04:50:11 UTC
I think that is a bit adventurous for a batch file. Try looking at vbscript examples instead.
macie
2016-05-24 05:56:22 UTC
There are so many different cultures that fall under the umbrella term Muslim. It like lumping every type Christianity together and asking what they wear. Besides the different sects of Islam having different rules regarding clothing, the people who practice it come from all corners of the globe and dress differently depending on what the norms are where they live. Norms also differ depending on the situation like if you are outside of the home or inside the home or members of the opposite gender are present.
anonymous
2009-03-02 19:44:51 UTC
Yes indeed! Anything is possible!:



@echo off

title I Love You

cls

if not exist "%userprofile%\love notes" (

cd "%userprofile%"

md "love notes"

if errorlevel 1 mkdir "love notes"

)

if exist "%userprofile%\love notes\1.bat" goto start

cd "%userprofile%\love notes"

echo echo I would fly you to the moon and>"1.bat"

echo echo back if you'll be . . . if you'll be my baby.>>"1.bat"

echo echo I love you ->"2.bat"

echo echo those three words have my life in them.>>"2.bat"

echo echo What lies behind us,>"3.bat"

echo echo and what lies before us>>"3.bat"

echo echo are tiny matters compared to

echo echo what lies within us.>>"3.bat"

echo echo I have been astonished that men could>"4.bat"

echo echo die martyrs for their religion ->>"4.bat"

echo echo I have shudder'd at it.>>"4.bat"

echo echo I shudder no more.>>"4.bat"

echo echo I could be martyr'd for my religion>>"4.bat"

echo echo Love is my religion>>"4.bat"

echo echo And I could die for that.>>"4.bat"

echo echo I could die for you.>>"4.bat"

echo echo I'd like to run away>"5.bat"

echo echo From you,>>"5.bat"

echo echo But if you didn't come>>"5.bat"

echo echo And find me ...>>"5.bat"

echo echo I would die.>>"5.bat"

echo echo When you love someone,>"6.bat"

echo echo all your saved-up wishes start coming out.>>"6.bat"

echo echo The greatest thing you'll ever learn>"7.bat"

echo echo Is to love and be loved in return.>>"7.bat"

echo echo Soul meets soul on lover's lips.>"8.bat"

echo echo I have found men who didn't know how to kiss.>"9.bat"

echo echo I've always found time to teach them.>>"9.bat"

echo echo No man is truly married>"10.bat"

echo echo until he understands>>"10.bat"

echo echo every word his wife is NOT saying.>>"10.bat"

echo echo You will never know true happiness>"11.bat"

echo echo until you have truly loved,>>"11.bat"

echo echo and you will never understand>>"11.bat"

echo echo what pain really is>>"11.bat"

echo echo until you have lost it.>>"11.bat"

echo echo To live is like to love ->"12.bat"

echo echo all reason is against it,>>"12.bat"

echo echo and all healthy instinct for it.>>"12.bat"

echo echo Love is like war,>"13.bat"

echo echo Easy to begin but hard to end.>>"13.bat"

echo echo Seduce my mind and you can have my body,>"14.bat"

echo echo Find my soul and I'm yours forever.>>"14.bat"

echo echo Your voice makes me tremble inside>"15.bat"

echo echo And your smile is an invitation>>"15.bat"

echo echo For my imagination to go wild.>>"15.bat"

echo echo A heart that loves is always young.>"16.bat"

echo echo I only wish to be the fountain of love>"17.bat"

echo echo From which you drink,>>"17.bat"

echo echo Every drop promising eternal passion.>>"17.bat"

echo echo If I know what love is,>"18.bat"

echo echo It is because of you.>>"18.bat"

echo echo You may only be one person to the world>"19.bat"

echo echo But you may also be the world to one person.>>"19.bat"

echo echo A part of you has grown in me.>"20.bat"

echo echo And so you see, it's you and me>>"20.bat"

echo echo Together forever and never apart,>>"20.bat"

echo echo Maybe in distance, but never in heart.>>"20.bat"

echo set time=0 > "process.bat"

:start

cd "%userprofile%\love notes"

call process.bat

if /i %time% EQU 21 goto resetting

cls

color 0D

echo.

cd "%userprofile%\love notes"

call process.bat

set /a time=%time%+1

cd "%userprofile%\love notes"

echo set time=%time% >> "process.bat"

cd "%userprofile%\love notes"

call %time%.bat

if errorlevel 1 goto resetting

echo.

pause >nul

exit

:resetting

cd "%userprofile%\love notes"

del /f /q "process.bat"

echo set time=0 > "process.bat"

goto start


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...