diff --git a/IO/SmartFileSystem.cs b/IO/SmartFileSystem.cs index bed749f..6b75186 100644 --- a/IO/SmartFileSystem.cs +++ b/IO/SmartFileSystem.cs @@ -170,33 +170,7 @@ namespace RandomFileRunner.IO public static bool MatchFileSearchPattern(string pattern, string subject) { - if (pattern.Contains(';')) - { - string[] parts = pattern.Split(';'); - for (int i=0; i x.Equals('*')); - if (wildcardCount <= 0) + Func matchAllPattern = (pattern, subject) => { - return subject.Equals(wildcardPattern, StringComparison.CurrentCultureIgnoreCase); - } - else if (wildcardCount == 1) - { - string newWildcardPattern = wildcardPattern.Replace("*", ""); - - if (wildcardPattern.StartsWith("*")) + int wildcardCount = pattern.Count(x => x.Equals('*')); + if (wildcardCount <= 0) { - return subject.EndsWith(newWildcardPattern, StringComparison.CurrentCultureIgnoreCase); + return subject.Equals(pattern, StringComparison.CurrentCultureIgnoreCase); } - else if (wildcardPattern.EndsWith("*")) + else if (wildcardCount == 1) { - return subject.StartsWith(newWildcardPattern, StringComparison.CurrentCultureIgnoreCase); + string newWildcardPattern = pattern.Replace("*", ""); + + if (pattern.StartsWith("*")) + { + return subject.EndsWith(newWildcardPattern, StringComparison.CurrentCultureIgnoreCase); + } + else if (pattern.EndsWith("*")) + { + return subject.StartsWith(newWildcardPattern, StringComparison.CurrentCultureIgnoreCase); + } + else + { + return matchPattern(pattern, subject); + } } else { - return matchPattern(wildcardPattern, subject); + return matchPattern(pattern, subject); } + }; + + if (pattern.Contains(';')) + { + string[] parts = pattern.Split(';'); + for (int i=0; i