Regex to find a file in folder

前端 未结 2 1567
轮回少年
轮回少年 2021-01-07 11:55

How to find all files matches a regex pattern in a folder?

Thanks

2条回答
  •  一生所求
    2021-01-07 12:10

    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 files = Directory
        .EnumerateFiles(@"c:\somePath")
        .Where(name => Regex.IsMatch(name, "SOME REGEX"));
    

提交回复
热议问题