I am working with an Artificial Intelligence on my computer and I have a simple command where I say “Play me a happy song”. What I would like that to do is trigger a batch file that will go to a file in which I have a variety of happy songs.
I don’t have a large amount knowledge with batch, especially when it comes to randoms. I just want it so it will randomly select the song from the file. Would this be better as a .vbs? I know nothing about those except how to make the file. If it’s the batch and you’re able to help me it would be greatly appreciated if you could explain a little bit of it to me so I can hopefully do more of these on my own.
The file that holds the mp3s is C:UsersptldkDocumentsBatchBatch SupportRandom Happy Music Playlist
Thank you
3
Answers
If you want to go through folders and files, consider to use
for
loop andforfiles
command. What you need to do is:1) Loops through the
Music_PATH
and search for only files with.mp3
extension.2) Create an array (even though batch don’t have this feature, but we can do it manually), and assign it with the file name.
%%~nxa
removes quotation marks and add extension at the end of the file name.3) Since
%random%
returns value between 0-32767, and we don’t need such big values,%random% %% VALUE(e.g: 10)
will return value between 0-9. This is good, because we are playing around with arrays, value 0 will be the 1st element of the array (which is the 1st mp3 file), and 0 is a part of the random range!4)
Start
the mp3 file with your default program (VLC, WMPlayer, etc…), Windows will ask for the default program if it’s necessary.You can give a try for this vbscript
I added a Randomize function to the great code from Hackoo.