List all files in folder with certain extension

I need VB .NET 2003 code for a windows form such that I can browse to folder location and then store in memory a list of all files with a certain extension.
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
Wayne Taylor (webtubbs)Commented:
Hi knowlton,

This line will store all files in a folder with a "xls" extension in a String array....

    Dim Files() as String = Directory.GetFiles("C:\FolderPath\", "*.xls")

Regards,

Wayne
0
 
Tom KnowltonWeb developerAuthor Commented:
What namespace is Directory found in?
0
 
Tom KnowltonWeb developerAuthor Commented:
Also

Once I call this:

Dim Files() as String = System.IO.Directory.GetFile(strPath, "*.mdb")


How do I loop through each file in Files( )?


Thanks...new to VB .NET
0
 
Wayne Taylor (webtubbs)Commented:
And to browse for the folder first....

        Dim FoldBrowser As New FolderBrowserDialog
        Dim Files() As String
        If FoldBrowser.ShowDialog = DialogResult.OK Then
            Files = System.IO.Directory.GetFiles(FoldBrowser.SelectedPath, "*.xls")
        End If

Wayne
0
 
Wayne Taylor (webtubbs)Commented:
Oops, sorry. Didn't realised you had posted.

To loop through each of the files once you've got the array, do something like this....

    For Each sFile As String In Files
         'sFile will return the FullPath to the file
    Next

Wayne
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.