Vb.net VB 2010如何使用返回随机子文件夹并在windows资源管理器中打开该文件夹
如何使用VB 2010返回随机子目录并在windows资源管理器中打开该目录 我有一个主目录C:\test\并希望打开或显示测试目录中随机子目录的路径(作为字符串) 理想情况下,当按下VB窗体上的按钮时,这会将我带到随机目录 我是Visual Basic新手,因此任何帮助都将非常有用。请尝试以下代码Vb.net VB 2010如何使用返回随机子文件夹并在windows资源管理器中打开该文件夹,vb.net,string,random,directory,Vb.net,String,Random,Directory,如何使用VB 2010返回随机子目录并在windows资源管理器中打开该目录 我有一个主目录C:\test\并希望打开或显示测试目录中随机子目录的路径(作为字符串) 理想情况下,当按下VB窗体上的按钮时,这会将我带到随机目录 我是Visual Basic新手,因此任何帮助都将非常有用。请尝试以下代码 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'Directory info for the starting folder.
Dim DirectoryInfo1 As New IO.DirectoryInfo("C:\test\")
'An array of all the subdirectories of the starting folder.
Dim Directories1() As IO.DirectoryInfo = DirectoryInfo1.GetDirectories("*", IO.SearchOption.AllDirectories)
'Random number generator.
Dim Random1 As New Random
'Gets a random index from the subdirectories array.
Dim RandomIndex1 As Integer = Random1.Next(0, Directories1.Length - 1)
'Shows the path of a random directory.
MsgBox(Directories1(RandomIndex1).FullName)
'Opens the random directory inside windows explorer.
Process.Start("explorer.exe", Directories1(RandomIndex1).FullName)
End Sub