FindInFiles

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


Syntax

FileSystem.FindInFiles(Directory, ContainsText, IgnoreCase, SearchOption)

FileSystem.FindInFiles(Directory, ContainsText, IgnoreCase, SearchOption, FileWildCard [, FileWildCard...])


Parameters


Directory

String, input



The directory to be searched.


ContainsText

String, input



The search text.


IgnoreCase

Boolean, input



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


SearchOption

Enumeration, input



Whether to include subfolders. Default is SearchTopLevelOnly.


FileWildCards

String(s), input



One or more patterns to be matched.


Remarks



SearchOption



SearchOption.SearchAllSubDirectories

Search the specified directory and all subdirectories within it. Default.


SearchOption.SearchTopLevelOnly

Search only the specified directory and exclude subdirectories.


Example

This example searches the specified directory for all files with .txt or .bat extensions containing the string "test" and displays the results in a message box:


Sub Main()

list = FileSystem.FindInFiles("C:\Users\Public\My Directory\", "test", True, SearchOption.SearchAllSubDirectories, "*.txt", "*.bat")

For Each name In list

MsgBox name

Next

End Sub