[RESOLVED] getting a random file name from a specific folder with VB 2010 express
I can get a file count in the folder and create a random number from that count, but this is all. Sorry I have NO code to attempt this.
Re: getting a random file name from a specific folder with VB 2010 express
GetFiles() returns an array of files. Use your random number to index into that array.
Alternatively, EnumerateFiles() returns an enumeration, you could count up to your random number and stop there.
But, considering that the way you count the files is probably to call GetFiles(), it'd be best to reuse that array.
Re: getting a random file name from a specific folder with VB 2010 express
How do I set the array size? How do I clear that array each time I've used it?
Re: getting a random file name from a specific folder with VB 2010 express
Quote:
Originally Posted by
GMTireman
How do I set the array size? How do I clear that array each time I've used it?
You don't set the array size or clear it. You call GetFiles and it returns an array. You can then use the Length of that array as the upper limit when call Random.Next. The sequence of events is:
Get the files - Directory.GetFiles or DirectoryInfo.GetFiles
Get the file count - Array.Length
Generate the random number - Random.Next
Get the random file - index the array using the random number
Re: getting a random file name from a specific folder with VB 2010 express
Re: getting a random file name from a specific folder with VB 2010 express
Quote:
Originally Posted by
GMTireman
ok (?)
purple [~]