How to determine if a File Matches a File Mask?

后端 未结 13 1645
清歌不尽
清歌不尽 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:39

    Use WildCardPattern class from System.Management.Automation available as NuGet package or in Windows PowerShell SDK.

    WildcardPattern pattern = new WildcardPattern("my*.txt");
    bool fits = pattern.IsMatch("myfile.txt");
    

提交回复
热议问题