由网友(我的霸道只對你)分享简介:如何找到的所有文件夹中匹配一个正则表达式?How to find all files matches a regex pattern in a folder?感谢推荐答案在的GetFiles 方法允许您指定通配符模式,但不是一个真正的正则表达式。另一种可能性是通过文件简单地循环,并验证其名称针对正则表达式Th...
如何找到的所有文件夹中匹配一个正则表达式?
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"));
相关推荐
最新文章