Link to home
Start Free TrialLog in
Avatar of cheshirefire
cheshirefire

asked on

Populate list box with multiple file types

I want to populate a list box from a directory with multiple particular file types, jpg or bmp or dwf only. can anyone suggest some code for vb express 2008.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.Text = "c:\test\"
        Dim files() As String = IO.Directory.GetFiles(TextBox1.Text)
        ListBox1.Items.Clear()
        For Each file As String In files
            ListBox1.Items.Add(IO.Path.GetFileName(file))
        Next
    End Sub

Open in new window

Avatar of alb66
alb66
Flag of Italy image

You can use the second parameter to specify the file type:

Dim files() As String = IO.Directory.GetFiles(TextBox1.Text, "*.jpg")

See
http://msdn.microsoft.com/en-us/library/ms143316.aspx
Avatar of cheshirefire
cheshirefire

ASKER

My apologies what I meant was *.jpg AND *.bmp AND *.dwf exclusively.

The directory has several other file types that another program uses i.e. htm's, txt's  so all I want are the above file types.

thanks
ASKER CERTIFIED SOLUTION
Avatar of alb66
alb66
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many thanks to you all, problem solved