Directory.GetFiles

官方文档:Directory.GetFiles Method (System.IO) | Microsoft Docs

public static string[] GetFiles(string path);
public static string[] GetFiles(string path, string searchPattern);
public static string[] GetFiles(string path, string searchPattern, EnumerationOptions enumerationOptions);
public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption);

搜索文件夹及文件夹下所有文件:

var files = System.IO.Directory.GetFiles("F:\\Xiang\\Docs", "*绩效*", SearchOption.AllDirectories);

searchPattern 可以是文本字符和通配符的组合,但它不支持正则表达式。 只允许以下通配符说明符 searchPattern

通配符说明器匹配
* (星号)该位置中的零个或多个字符。
? (问号)该位置中的零个或一个字符。

Characters other than the wildcard are literal characters. For example, the searchPattern string "*t" searches for all names in path ending with the letter "t". The searchPattern string "s*" searches for all names in path beginning with the letter "s".

searchPattern cannot end in two periods ("..") or contain two periods ("..") followed by DirectorySeparatorChar or AltDirectorySeparatorChar, nor can it contain any invalid characters. You can query for invalid characters by using the GetInvalidPathChars method.