HELP!
I'd like a script to play a random .wav file from a specified directory. How can this be done?
I'd like a script to play a random .wav file from a specified directory. How can this be done?
If this is your first visit, be sure to check out the FAQ. You must register before you can post.
IMPORTANT: Your first post will be checked for appropriate content. This may take a bit of time.
sub main() dim fs, root, ndx, randomNdx dim objFile, colFiles, strFileName ndx=0 set fs = createObject("scripting.filesystemobject") set root = fs.getFolder("C:\Program Files\HomeSeer 2\Sounds\Birds") Set colFiles = root.Files randomNdx = cint(GetRandomNumber(1,cint(colFiles.count))) For Each objFile in colFiles if ndx=randomNdx then if lcase(fs.getExtensionName(objFile))="wav" then strFileName = fs.getAbsolutePathName(objFile) end if exit for end if ndx=ndx+1 Next hs.writeLog "RandomBirdSound","Found " & ndx & " files. Playing:" & strFileName hs.mediafilename = strFileName hs.mediaplay end sub Function GetRandomNumber(lowerbound,upperbound) Randomize GetRandomNumber = Int((upperbound - lowerbound + 1) * Rnd + lowerbound) End Function
Comment