mike mcintyre's

.N e t J o u r n a l

This blog hosted by:
http://blogs.vbcity.com      
  Home :: Syndication  :: Login

JulAugust 2006Sep
SMTWTFS
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

Archives

Topics

Source Code

Wednesday, August 30, 2006 #

Dowload Source Code: Source Code

Use the Visual Basic 2005 My.Compuer.FileSystem.GetFiles method to search for files.

The My.Computer.FileSystem.GetFiles Method returns a read-only collection of strings representing the name of the files within a directory. Use the wildCards parameter of the GetFiles method to specify a specific file name pattern. Set the searchType parameter of the GetFiles method to search only the root of a directory or a directory and all its subdirectories.

EXAMPLE CODE

    Protected Function SearchForFiles(ByVal directory As String, ByVal searchOption As Microsoft.VisualBasic.FileIO.SearchOption, ByVal wildCards As String) As String

        Dim returnValue As String = ""

        Try

            For Each foundFile As String In My.Computer.FileSystem.GetFiles(directory, searchOption, wildCards)

                returnValue &= foundFile & Environment.NewLine

            Next

        Catch ex As Exception

            MessageBox.Show("Exception thrown: " & ex.Message)

        End Try

 

        Return returnValue

    End Function

Click the link above to download Visual Basic source code in a Visual Studio 2005 solution which demonstrates how to use the My.Computer.FileSystem GetFiles method to search for files.

Mike McIntyre

Get Dot Net Code

posted @ 2:11 PM