Hello I’m trying to complete a batchfile im working on.
I have a library of motivational quotes textfiles, and i want my batchfile to pick one random quote textfile and display it in the command window. with the command type i guess.
my path to the folder with the quotes is:
C:\Users\niv\Documents\test\scripts\quotes
inside there is :
Quote 1.txt
Quote 2.txt
Quote 3.txt.
i did the command: `type “C:\Users\niv\Documents\test\scripts\quotes\quote1.txt”
that only displayed the selected quote1.txt ofcourse.
If possible i want to get the selected Quote-text file to be a variable so i can use it for different tasks in my batchfile like:
after receiving the selected quote do this command with a program that makes it possible for my computer to read anything after “”. like this
%speech% "%quotes%"
the %speech% lets my computer speak whats inside the quotation marks.
i hope you can understand what im trying to accomplish here if not just ask 🙂
I am assuming each quote is contained in a single line in each file. I recommend placing all the quotes in a single file named quotes.txt, with one quote per line. This should make it easier to maintain the quotes. Then all you need is code that will count the number of lines in the file, and then randomly pick a line between 1 and count.
The FIND /C command can count the number of lines in a file.
The
%RANDOM%dynamic variable gives a pseudo random number between 0 and 32767, and the modulo SET /A operator can be used to convert the value into a number between 0 and count-1.The FOR /F command reads lines from a file, and you can use the SKIP option to skip a random number of lines.
quotes.txt
randomQuote.bat