This topic has not yet been rated - Rate this topic

FileSystem.FindInFiles Method (String, String, Boolean, SearchOption)

Note: This method is new in the .NET Framework version 2.0.

Returns a read-only collection of strings representing the names of files containing the specified text.

Namespace: Microsoft.VisualBasic.FileIO
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public static ReadOnlyCollection<string> FindInFiles (
	string directory,
	string containsText,
	bool ignoreCase,
	SearchOption searchType
)
public static ReadOnlyCollection<String> FindInFiles (
	String directory, 
	String containsText, 
	boolean ignoreCase, 
	SearchOption searchType
)
public static function FindInFiles (
	directory : String, 
	containsText : String, 
	ignoreCase : boolean, 
	searchType : SearchOption
) : ReadOnlyCollection<String>

Parameters

directory

String. The directory to be searched. Required.

containsText

String. The search text. Required.

ignoreCase

Boolean. Whether the search should be case-sensitive or not. Default is True. Required.

searchType

SearchOption Enumeration. Whether to include subfolders. Default is SearchOption.SearchTopLevelOnly. Required.

Return Value

Read-only collection of type String.

For more detailed information, see the Visual Basic topic My.Computer.FileSystem.FindInFiles Method.

An empty collection is returned if no files matching the specified pattern are found.

The following table lists examples of tasks involving the My.Computer.FileSystem.FindInFiles method.

To

See

Search a directory for files containing a specific string

Walkthrough: Manipulating Files and Directories in Visual Basic

This example searches the directory C:\TestDir for any files containing the string "sample string" and displays the results in ListBox1.

Dim list As System.Collections.ObjectModel.ReadOnlyCollection _
(Of String)
list = My.Computer.FileSystem.FindInFiles("C:\TestDir", _
 "sample string", True, FileIO.SearchOption.SearchTopLevelOnly)
For Each name As String In list
   ListBox1.Items.Add(name)
Next

In order to work, the project must contain a ListBox named ListBox1.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.