I am making this program that randomly picks a file (not a folder) from a directory and produces a message box with that file as text. I am currently using this:
Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each item In Directory.GetFiles("Directory")
Dim filename As String = Path.GetFileName(item)
MsgBox(filename)
Next
End Sub
End Class
However this prints the files in the order they were (from top to bottom) in that directory. Is there any way to print the files from a directory in a random pattern? For example, if a directory has files F1
, F2
and F3
. The code I use prints them out in order of F1
, F2
and F3
. Whereas I would like a program that prints them in a random order, such as F2
, F1
and F3
. Also, if it's possible, I would only like the program to output one file name and stop, rather than it continuously going through the directory. For example, the message box would say F2
and close, rather than going through the list of files.