Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual Basic
 How to: Find Files with a Specific ...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Basic Application Development
How to: Find Files with a Specific Pattern in Visual Basic

The My.Computer.FileSystem.GetFiles Method returns a read-only collection of strings representing the path names for the files. You can use the wildCards parameter to specify a specific pattern. If you would like to include subdirectories in the search, set the searchType parameter to SearchOption.SearchAllSubDirectories.

An empty collection is returned if no files matching the specified pattern are found.

To find files with a specified pattern

  • Use the GetFiles method, supplying the name and path of the directory you want to search and specifying the pattern. The following example returns all files with the extension .dll in the directory and adds them to ListBox1.

    Visual Basic
    For Each foundFile As String In My.Computer.FileSystem.GetFiles( _
        My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
        Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.dll")
    
        Listbox1.Items.Add(foundFile)
    Next
    
    

The following conditions may cause an exception:

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker