如何在C#目录中搜索多个文件? [英] How to search multiple files with in a directory in C#?
本文介绍了如何在C#目录中搜索多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C#中的目录中搜索多个文件?
我尝试下面的代码
string [] fileList = System.IO.Directory.GetFiles(COMMON.FPPath, C200 | C220 *,SearchOption.AllDirectories);
但我在路径中收到错误的非法字符。
解决方案
试试这个..
1)你可以用多个过滤器调用Directory.GetFiles()吗?
2 )搜索目录C#中的文件
如果您收到一条消息,指出您在路径中有非法字符,则COMMON.FPPath
的内容错误。使用调试器,查看变量的内容。
搜索多个过滤器后,您无法将多个过滤器组合到一个搜索中。您必须使用多个搜索或单独使用单个搜索过滤器。一个很好的方法是使用LINQ。看看你能用多个过滤器调用Directory.GetFiles()吗? [ ^ ]
第三件事是,如果可能的话,使用 EnumerateFiles [ ^ ]这将比GetFiles
How to search multiple files with in a directory in C#?
I tried below code
string[] fileList = System.IO.Directory.GetFiles(COMMON.FPPath, "C200|C220*", SearchOption.AllDirectories);
But I am getting the error Illegal characters in Path.
解决方案
Hi,
Try this..
1 )Can you call Directory.GetFiles() with multiple filters?
2 )search files in directory C#
If you're getting a message saying that you have illegal characters in the path then the content ofCOMMON.FPPath
s wrong. Using debugger, have a look at the content of the variable.
What comes to searching for multiple filters, you can't combine multiple filters into a single search. You have to either use multiple searches or using a single search filter sepearately. One nice way is to use LINQ. Have a look at Can you call Directory.GetFiles() with multiple filters?[^]
The third thing is that if possible, use EnumerateFiles[^] which would be faster thanGetFiles
这篇关于如何在C#目录中搜索多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文