正则表达式来查找文件夹中的文件 [英] Regex to find a file in folder
本文介绍了正则表达式来查找文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何找到的所有文件夹中匹配一个正则表达式?
How to find all files matches a regex pattern in a folder?
感谢
推荐答案
在的GetFiles 方法允许您指定通配符模式,但不是一个真正的正则表达式。另一种可能性是通过文件简单地循环,并验证其名称针对正则表达式
The GetFiles method allows you to specify a wildcard pattern but not really a regex. Another possibility is to simply loop through the files and validate their name against a regex.
IEnumerable<string> files = Directory
.EnumerateFiles(@"c:\somePath")
.Where(name => Regex.IsMatch(name, "SOME REGEX"));
这篇关于正则表达式来查找文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文