Results 1 to 3 of 3

Thread: list all files in a directory to a list box

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    Hi. I know this has been answered before, but i just can't find it.

    Can anybody please let me know what function (maybe an API) will allow me to get the names of all files in a given directory listed into a list box. ??

    I appreciate any help on this.

    Thanks

  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    Add a listbox to your form and paste this code.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
      Call p_List_Directories("C:\")
    End Sub
    
    Sub p_List_Directories(str_Path As String)
      'PURPOSE: Add Back Slash
      If Right(str_Path, 1) <> "\" Then str_Path = str_Path & "\"
      
      'PURPOSE: Get the first file
      str_Path = Dir(str_Path & "*.*")
      Do Until str_Path = ""
        
        'PURPOSE: Add it to the Listbox
        List1.AddItem StrConv(str_Path, vbProperCase)
        
        'PURPOSE: Get the next file
        str_Path = Dir()
      Loop
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  3. #3

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    That was it!


    Thanks, Nitro

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