如何过滤掉C#中的文件夹名称?

hei*_*nst 0 .net c# string directory filter

我有代码搜索目录并挑选出所有文件夹,但我只想要它选择那些以数据开头的文件夹.我该怎么办?

以下是我通过目录的代码:

    string[] filePaths = Directory.GetDirectories(defaultPath).Where(Data => !Data.EndsWith(".")).ToArray();
Run Code Online (Sandbox Code Playgroud)

Dou*_*las 10

无需使用LINQ; GetDirectories支持搜索模式,并且可能明显更快,因为枚举.NET中的结果之前,文件系统可以进行过滤.

string[] filePaths = Directory.GetDirectories(defaultPath, "Data*");
Run Code Online (Sandbox Code Playgroud)

请注意,这*是一个匹配零个或多个字符的通配符.