Results 1 to 6 of 6

Thread: Get a list of all files in dir

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275

    Get a list of all files in dir

    How can I populate a listbox with all the files in a listbox?

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. ' make a reference to a directory
    2.         Dim di As New DirectoryInfo("c:\")
    3.         Dim diArr As DirectoryInfo() = di.GetDirectories()
    4.         Dim diar1 As FileInfo() = di.GetFiles()
    5.    
    6.  
    7.      
    8.  
    9.         ' list the names of all the subdirectories in the specified directory
    10.         Dim dri As DirectoryInfo
    11.        
    12.         'BeginUpdate method freezes painting while you add items
    13.         ListBox1.BeginUpdate()
    14.         For Each dri In diArr
    15.             ListBox1.Items.Add(dri)
    16.         Next
    17.  
    18.         'EndUpdate resumes painting of listbox
    19.         ListBox1.EndUpdate()
    20.      
    21.         'list the names of all files in the specified directory
    22.         Dim dra As FileInfo
    23.         For Each dra In diar1
    24.             listbox2.items.add(dra)
    25.         Next
    Last edited by nemaroller; Jan 31st, 2003 at 10:51 AM.

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    lol... i just found this stuff I had filed away in my 'common code snippets'
    VB Code:
    1. [b]'Adding Files in a directory to a listbox[/b]
    2.  
    3. ListBox1.DataSource = Directory.GetFiles("C:\")
    4.  
    5.  
    6. [b]'Adding subdirectories of a directory to a listbox[/b]
    7.  
    8. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    9.         Dim r As String()
    10.         r = Directory.GetDirectories("C:\")
    11.         ListBox1.DataSource = r
    12.        
    13. End Sub

  4. #4
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    lol... i just found this stuff I had filed away in my 'common code snippets'
    Why not include them in the VBCodeBook.NET program to help other users? If you wish to send them, i'll include them in a future release.

    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well, consider it submitted

  6. #6
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Thanks
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

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