FindInFiles Method


FindInFiles Method

Location

My.Computer.FileSystem.FindInFiles

Syntax

     Dim result As System.Collections.ObjectModel.ReadOnlyCollection( _         Of String) = My.Computer.FileSystem.FindInFiles(path, _     containsText, ignoreCase, searchType[, wildcard]) 


path (required; String)

The path to the directory that includes the files to search.


containsText (required; String)

The text to search for in each file.


ignoreCase (required; Boolean)

Indicates whether the search should be case-sensitive (False) or case-insensitive (TRue).


searchType (optional; SearchOption enumeration)

The type of search to perform. One of the following Microsoft.VisualBasic.FileIO.SearchOption enumeration values.

Value

Description

SearchAllSubDirectories

Includes all files found directly under the specified path and also in all descendant subdirectories below the specified path

SearchTopLevelOnly

Includes only those files found immediately under the specified path; does not include files found in other descendant subdirectories



wildcard (optional; String)

A pattern used to match file names. If missing, all names are matched. Use the asterisk character (*) to match zero or more characters or the question mark character (?) to match exactly one character.

Description

The FindInFiles method returns a collection of strings, each one the name of a file within the specified directory that includes the specified search text. The set of files to search may be limited using the wildcard parameter. If no searched files include the specified search text, an empty collection is returned.

Usage at a Glance

  • The returned collection is read-only.

  • An exception is thrown if the supplied path is missing or invalid or if an invalid wildcard expression appears.

  • An exception is thrown if the user lacks sufficient file system privileges.

Example

The following statement searches for files that contain the text "virus" (independent of case) in the current user's MyDocuments folder, ignoring any subdirectories.

     Dim result As System.Collections.ObjectModel.ReadOnlyCollection( _        Of String) = My.Computer.FileSystem.FindInFiles( _        My.Computer.FileSystem.SpecialDirectories.MyDocuments, _        "VIRUS", True, FileIO.SearchOption.SearchTopLevelOnly) 

Related Framework Entries

  • Microsoft.VisualBasic.MyServices.FileSystemProxy.FindInFiles Method

  • Microsoft.VisualBasic.FileIO.FileSystem.FindInFiles Method

See Also

CurrentDirectory Property, Drives Property, FileSystem Object, GetDirectories Method, GetDirectoryInfo Method, GetDriveInfo Method, GetFileInfo Method, GetFiles Method, GetTempFileName Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net