H o m e

 

F R E E   D O W N L O A D

Search For Files With The Visual Basic 2005 My Computer FileSystem Object  

8/31/2006 SearchForFilesWithVisualBasicMyFileSystem.zip

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

    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

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 the directory or all subdirectories.

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.

For more information visit the My.Computer.FileSystem.GetFiles Method article on Microsoft's MSDN2 web site.

Get Dot Net Code is a web site full of free and pay for use Visual Basic source code for Visual Basic programmers.

 

Copyright © 2001-2006 aZ Software Developers. All rights reserved.

.