我正在尝试过滤方法的输出,因此只会返回带有“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-*.*");
引用:
* - 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/