Monday, July 27, 2009

FindInFiles Method in VisualStudio

While using Windows you might have came through the Search Option . Where you can give a text and force the windows to find that text in files.

These method can be used in Visual Studio C#/VB.Net

Visual Studio has a method called

My.Computer.FileSystem.FindInFiles Method


Which offers to use the method used by the windows

Example

Dim findstring As String = "and"
Dim sFileList As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.FindInFiles("D:\", findstring, True, FileIO.SearchOption.SearchTopLevelOnly)


Outputs
The Files list




Arguments for the commands are
directory - Directory to be searched
containsText - Text to be searched in the documents
ignoreCase - Case dependant search or not(True/False)
searchType - SearchOption
Enumeration(SearchAllSubDirectories,SearchTopLevelOnly).
Whether to include
subfolders.Default is SearchOption.SearchTopLevelOnly. Required.

No comments: