mike mcintyre's

.N e t J o u r n a l

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

AprMay 2008Jun
SMTWTFS
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

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