How to determine if a File Matches a File Mask?

后端 未结 13 1646
清歌不尽
清歌不尽 2020-12-14 07:14

I need to decide whether file name fits to file mask. The file mask could contain * or ? characters. Is there any simple solution for this?

bool bFits = Fits         


        
13条回答
  •  感情败类
    2020-12-14 07:32

    Nissim mentioned the PatternMatcher Class in his answer...

    There is an explanation available here:

    http://referencesource.microsoft.com/#System/services/io/system/io/PatternMatcher.cs

    So you don't have to use the reflected code and guess how it works.

    Also, I think using this code is probably the best solution, because it guarantees consistent behavior when using the same pattern in your comparisons and in Framework methods like GetFiles().

提交回复
热议问题