What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Random Selection

Random Selection
Author: Message:
mad_willsy
Junior Member
**


Posts: 21
34 / Male / Flag
Joined: Jan 2007
O.P. Random Selection
How do i select a random file from a directory?
Backthebulls.com - Free online games
Upload your own stuff - free!
02-03-2007 10:22 PM
Profile PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: Random Selection
put all the filenames in an array and choose the index with a random number.
[Image: 1-0.png]
             
02-04-2007 12:04 AM
Profile PM Web Find Quote Report
mad_willsy
Junior Member
**


Posts: 21
34 / Male / Flag
Joined: Jan 2007
O.P. RE: Random Selection
Can i have a snippet please - I only know php!

I need to...

1. Open the folder
2. Put all filenames into an array
3. Select a random file
4. Put it into a variable, say DPName.

This post was edited on 02-04-2007 at 11:28 AM by mad_willsy.
Backthebulls.com - Free online games
Upload your own stuff - free!
02-04-2007 11:26 AM
Profile PM Web Find Quote Report
Felu
Veteran Member
*****


Posts: 2223
Reputation: 72
30 / Male / Flag
Joined: Apr 2006
Status: Away
RE: Random Selection
code:
function RandomFile(Folder){//The Function
    FileArray = new Array();//The Array
    for(var e = new Enumerator(fso.GetFolder(Folder).Files); !e.atEnd(); e.moveNext())//The Enumerator
        FileArray.push(e.item());//Push the files into the array
    File = FileArray[Math.floor(Math.random()*FileArray.length)];//Getting a Random File
    return File;//Return the random File
}

This post was edited on 02-04-2007 at 01:48 PM by Felu.
02-04-2007 01:27 PM
Profile E-Mail PM Web Find Quote Report
hmaster
Senior Member
****

Avatar

Posts: 716
Reputation: 24
33 / Male / Flag
Joined: Nov 2004
RE: Random Selection
You forgot to declare the fso variable:
code:
var fso = new ActiveXObject("Scripting.FileSystemObject");

This post was edited on 02-04-2007 at 01:55 PM by hmaster.
[Image: sig.png]
02-04-2007 01:54 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Random Selection
Also note that the returned object is a File object. Check MSDN for the available methods and properties of this kind of object. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-04-2007 05:04 PM
Profile E-Mail PM Web Find Quote Report
mad_willsy
Junior Member
**


Posts: 21
34 / Male / Flag
Joined: Jan 2007
O.P. RE: Random Selection
Sweet, thanks.
Backthebulls.com - Free online games
Upload your own stuff - free!
02-05-2007 07:11 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On