Results 1 to 3 of 3

Thread: [RESOLVED] Get text files in folder

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    98

    Resolved [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.

  2. #2

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width