Multiple file-extensions searchPattern for System.IO.Directory.GetFiles

前端 未结 20 2538
名媛妹妹
名媛妹妹 2020-11-27 11:08

What is the syntax for setting multiple file-extensions as searchPattern on Directory.GetFiles()? For example filtering out files

20条回答
  •  死守一世寂寞
    2020-11-27 11:50

    I fear you will have to do somthing like this, I mutated the regex from here.

    var searchPattern = new Regex(
        @"$(?<=\.(aspx|ascx))", 
        RegexOptions.IgnoreCase);
    var files = Directory.EnumerateFiles(path)
        .Where(f => searchPattern.IsMatch(f))
        .ToList();
    

提交回复
热议问题