Results 1 to 3 of 3

Thread: how do I display the items in a folder in a text box?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    82

    Question how do I display the items in a folder in a text box?

    I know I need a folder, c:\windows\desktop
    I know I need a listbox, listThis
    I know I need to open the folder so I can get the files within and I am pretty sure I need to use a loop to display the folder items in the list box, listThis

    all of this under one control button I have tried something like this:

    Private Sub getFilesInFolder_Click()
    searchPath = "c:\windows\desktop"

    for i = 0 to listThis
    listThis.additem = searchPath
    next i

    and I get an error. I know I am missing something, and probably got somethings messed up.

    What am I missing?

  2. #2
    AIS_DK
    Guest
    What you have done doesn't make sense. So just to ******** is a little.
    Your for loop, you go from i = 0 to the name of your listbox, which is properly what causes your error.
    Secondly if your for-loop had worked, you are only adding the string containing "C:\Windows\Desktop" to the listbox.

    THis code should give you what you wan't:
    Code:
    Dim strFileFound As String
    
    strFileFound = Dir("C:\Windows\Desktop\", vbDirectory) 'Includes files and folders
    
    Do While strFileFound <> ""
        If strFileFound <> "." And strFileFound <> ".." Then
            Me.List1.AddItem strFileFound
        End If
        strFileFound = Dir
    Loop

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    82
    THANK YOU SOOO MUCH! I have been going nuts trying to figure this one out. Just what I needed

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