Uredi

Deli z drugimi prek


FileSystemProxy.FindInFiles Method

Definition

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

Overloads

FindInFiles(String, String, Boolean, SearchOption)

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

FindInFiles(String, String, Boolean, SearchOption, String[])

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

FindInFiles(String, String, Boolean, SearchOption)

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

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ FindInFiles(System::String ^ directory, System::String ^ containsText, bool ignoreCase, Microsoft::VisualBasic::FileIO::SearchOption searchType);
public System.Collections.ObjectModel.ReadOnlyCollection<string> FindInFiles (string directory, string containsText, bool ignoreCase, Microsoft.VisualBasic.FileIO.SearchOption searchType);
member this.FindInFiles : string * string * bool * Microsoft.VisualBasic.FileIO.SearchOption -> System.Collections.ObjectModel.ReadOnlyCollection<string>
Public Function FindInFiles (directory As String, containsText As String, ignoreCase As Boolean, searchType As SearchOption) As ReadOnlyCollection(Of String)

Parameters

directory
String

The directory to be searched.

containsText
String

The search text.

ignoreCase
Boolean

True if the search should be case-sensitive; otherwise False. Default is True.

searchType
SearchOption

Whether to include subfolders. Default is SearchOption.SearchTopLevelOnly.

Returns

Read-only collection of the names of files containing the specified text.

Exceptions

The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \.</code>).

directory is Nothing or an empty string.

The specified directory does not exist.

The specified directory points to an existing file.

The path exceeds the system-defined maximum length.

The specified directory path contains a colon (:) or is in an invalid format.

The user lacks necessary permissions to view the path.

The user lacks necessary permissions.

Examples

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 In list
    ListBox1.Items.Add(name)
Next

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

Remarks

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

See also

Applies to

FindInFiles(String, String, Boolean, SearchOption, String[])

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

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::String ^> ^ FindInFiles(System::String ^ directory, System::String ^ containsText, bool ignoreCase, Microsoft::VisualBasic::FileIO::SearchOption searchType, ... cli::array <System::String ^> ^ fileWildcards);
public System.Collections.ObjectModel.ReadOnlyCollection<string> FindInFiles (string directory, string containsText, bool ignoreCase, Microsoft.VisualBasic.FileIO.SearchOption searchType, params string[] fileWildcards);
member this.FindInFiles : string * string * bool * Microsoft.VisualBasic.FileIO.SearchOption * string[] -> System.Collections.ObjectModel.ReadOnlyCollection<string>
Public Function FindInFiles (directory As String, containsText As String, ignoreCase As Boolean, searchType As SearchOption, ParamArray fileWildcards As String()) As ReadOnlyCollection(Of String)

Parameters

directory
String

The directory to be searched.

containsText
String

The search text.

ignoreCase
Boolean

True if the search should be case-sensitive; otherwise False. Default is True.

searchType
SearchOption

Whether to include subfolders. Default is SearchOption.SearchTopLevelOnly.

fileWildcards
String[]

Pattern to be matched.

Returns

Read-only collection of the names of files containing the specified text.

Exceptions

The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \.</code>).

directory is Nothing or an empty string.

The specified directory does not exist.

The specified directory points to an existing file.

The path exceeds the system-defined maximum length.

The specified directory path contains a colon (:) or is in an invalid format.

The user lacks necessary permissions to view the path.

The user lacks necessary permissions.

Examples

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 In list
    ListBox1.Items.Add(name)
Next

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

Remarks

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

See also

Applies to