You must be searching for
Directory.GetFiles(path, searchPattern, SearchOption)[
^] overload of Directory.GetFiles().
Try this way:
string[] files = directory.GetFiles(@"c:\windows\system32", "*.dll", SearchOption.AllDirectories);
return files.Length;
Here
Path
specifies the path,
searchPattern
specifies your wildcards (e.g., *, *.format) and
SearchOption
provides the option to include
subdirectories.
The Length property of the return array of this search will provide the proper file count for your particular search pattern and option.
Also check similar answer
here[
^]