mike mcintyre's

.N e t J o u r n a l

vbCity Blogs moved to:
http://cs.vbcity.com/blogs
  Home :: Syndication  :: Login

OctNovember 2009Dec
SMTWTFS
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

Archives

Topics

Source Code

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 on Wednesday, August 30, 2006 2:11 PM