c# - 在 C# 中列出目录时如何过滤文件

标签 c# .net windows

我正在尝试过滤方法的输出,因此只会返回带有“FF-”前缀的文件。

我的代码如下:

 DirectoryInfo dinfo = new DirectoryInfo(@"C:\Windows\system32\tasks");
            FileInfo[] Files = dinfo.GetFiles("*.*");
            foreach (FileInfo file in Files)
            {
                listBox1.Items.Add(file.Name);
            }

最佳答案

像这样?

FileInfo[] Files = dinfo.GetFiles("FF-*.*");

Directory.GetFiles Method

引用:

* - Zero or more characters.  
? - Exactly zero or one character. 

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".

关于c# - 在 C# 中列出目录时如何过滤文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6479326/

相关文章:

c# - 在设置另一个VisualState之后,如何维护VisualState触发器所做的更改?

c# - 让方法对 DLL 中的 PropertyChanged 使用react

.net - 在 Web.Config 中存储来自电子邮件友好显示名称的 Smtp

java - 获取上下文菜单中命令参数中的文件名

linux - 绕过 Domain 在 WinEXE 中的使用

c# - LINQ 动态库 : How to extract count and list from IQueryable

c# - 用于呈现新闻和类别的 Razor ,多个模型

c# - 非常奇怪且严重的多线程不一致问题c#

c# - Word 2007 为操作形状但在 Word 2010 中正常工作的互操作代码引发异常

windows - Julia 中的 CUDA 测试 - GPU 利用率非常低