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

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>
Not applicable.



String. The directory to be searched. Required.


String. The search text. Required.


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


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 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.



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

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

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions