using System.Text; using System.Text.RegularExpressions; namespace IceImportDAL.CustomCode.RemoteFileSources; // Simple glob-style matcher for MICEMAPFTPSOURCE.FILENAMEPATTERN (e.g. "*.csv", "invoice_????.xml") // — deliberately not a regex (no new dependency, and admins configuring FileNamePattern should // never need to know regex escaping rules). Supports '*' (any run of characters) and '?' (any // single character); every other character is matched literally and case-insensitively. internal static class WildcardPatternMatcher { public static bool IsMatch(string fileName, string pattern) { if (string.IsNullOrWhiteSpace(pattern)) return true; // no pattern configured — match everything var regexPattern = GlobToRegex(pattern); return Regex.IsMatch(fileName, regexPattern, RegexOptions.IgnoreCase); } private static string GlobToRegex(string glob) { var sb = new StringBuilder("^"); foreach (var c in glob) { switch (c) { case '*': sb.Append(".*"); break; case '?': sb.Append('.'); break; default: sb.Append(Regex.Escape(c.ToString())); break; } } sb.Append('$'); return sb.ToString(); } }