How do I check if a filename matches a wildcard pattern

前端 未结 8 1561
青春惊慌失措
青春惊慌失措 2020-11-30 06:16

I\'ve got a wildcard pattern, perhaps \"*.txt\" or \"POS??.dat\".

I also have list of filenames in memory that I need to compare to that pattern.

How would

8条回答
  •  醉梦人生
    2020-11-30 06:58

    Some kind of regex/glob is the way to go, but there are some subtleties; your question indicates you want identical semantics to IO.DirectoryInfo.GetFiles. That could be a challenge, because of the special cases involving 8.3 vs. long file names and the like. The whole story is on MSDN.

    If you don't need an exact behavioral match, there are a couple of good SO questions:

    glob pattern matching in .NET
    How to implement glob in C#

提交回复
热议问题