[RESOLVED] Get text files in folder
Hi, i have a folder on my PC and i want to get all the text files from that folder and display them in a listbox.
I tried using FileSystemObject by doing something like this
Code:
Dim fso As New FileSystemObject
Dim Files As String
Files = fso.GetFile(App.Path & "\" & "*.txt*")
MsgBox Files
but it didnt work.
And in the above code I just tried to get it to display in a msgbox.
Re: Get text files in folder
Have a very good look at this sample.
Re: Get text files in folder
Use Dir() is much easier in this case:
Code:
Dim sFName As String
Dim sFolder As String
Dim sFileList As String
sFolder = App.Path
sFName = Dir(sFolder & "\*.txt")
While sFName <> ""
sFileList = sFileList & sFName & vbCr
'-- replace above line with the line below if you want to display in ListBox1
'ListBox1.AddItem sFName
sFName = Dir()
Wend
MsgBox sFileList