Problem with code: My.Computer.FileSystem
Im trying to make a little program that list all folders/subfolders in a directory that I specify in a TextBox, and I also want the program to show a messagebox If i write something wrong in the textbox like folders that not exits etc. but I cant get this to work.
This is my code so far:
Public Class Form1
Private Sub btnListFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVisInnhold.Click
'Create variabel
Dim strFolder As String
Dim strFolderName As String
'Textbox for writing folder/station name
strFolderName = TextBox1.Text
'list all folders
For Each strFolder In _
My.Computer.FileSystem.GetDirectories(strFolderNam e)
If My.Computer.FileSystem.DirectoryExists(strFolder) Then
'Add the item to the list
ListBox1.Items.Add(strFolder)
'Tell the user
MessageBox.Show("Found it, exiting the loop now.", "Info")
'Quit the loop early
Else
MessageBox.Show("Folder/station does not exists.", "Error")
Exit For
End If
Next
End Sub
|