|
-
Nov 1st, 2015, 03:28 PM
#1
Thread Starter
Junior Member
[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.
-
Nov 1st, 2015, 03:41 PM
#2
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.
This answer is wrong. You should be using TableAdapter and Dictionaries instead.
-
Nov 1st, 2015, 04:15 PM
#3
Thread Starter
Junior Member
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?
-
Nov 1st, 2015, 11:40 PM
#4
Re: getting a random file name from a specific folder with VB 2010 express
 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
-
Nov 2nd, 2015, 03:11 AM
#5
Thread Starter
Junior Member
Re: getting a random file name from a specific folder with VB 2010 express
-
Nov 2nd, 2015, 03:42 AM
#6
Re: getting a random file name from a specific folder with VB 2010 express
 Originally Posted by GMTireman
ok (?)
purple [~]
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|