Displaying files in a directory as a string

Moocow

Member
Joined
Jan 7, 2007
Messages
8
Programming Experience
Beginner
This is probably easy for you guys, but i can't work out how i would display all the files of a directory in a rich text box - I just want it to find the files in it and display them in a text box like:

Plugin1.Txt
Plugin2.Txt
Plugin3.Txt

Dim GetFiles As String
GetFiles = System.IO.Directory.GetFiles("C:/Generic/Plugins/")

I started with that. There wasn't any errors. So now i used a function.

Function WriteToWindow(ByVal var)
My.Forms.Form1.RichTextBox1.AppendText(var & vbCrLf)
End Function

That wouldn't work - As the files seem to be an array or something i haven't learnt yet. What do i do?
 
For Each s As String in System.IO.Directory.GetFiles("C:/Generic/Plugins/")
myTextBox.Lines.Append(s)
Next s
 
I'm not sure why you'd want to write them to a RichTextBox. But the code to get the files is like so...

VB.NET:
Dim di As New IO.DirectoryInfo("C:/Generic/Plugins/")
    Dim diar1 As IO.FileInfo() = di.GetFiles()
    Dim dra As IO.FileInfo
 
   'diar1 is an array of the files. To add them to a listbox we would do like so..
 
    For Each dra In diar1
        ListBox1.Items.Add(dra)
    Next
 
' You can get other info i.e FileName using the fileinfo object..
 
dra.fullname
 
'for example

This was striaght out of an app i wrote. You can change it to add them to a RichTextBox if you like.
 
Back
Top