For file globbing you can use the following function. Credits go to to Erwin at
http://www.codeproject.com/KB/string/wildcmp.aspx
public static class StringExtensions
{
public static bool WildcardMatch(this string str, string compare, bool ignoreCase)
{
if (ignoreCase)
return str.ToLower().WildcardMatch(compare.ToLower());
else
return str.WildcardMatch(compare);
}
public static bool WildcardMatch(this string str, string compare)
{
if (string.IsNullOrEmpty(compare))
return str.Length == 0;
int pS = 0;
int pW = 0;
int lS = str.Length;
int lW = compare.Length;
while (pS < lS && pW < lW && compare[pW] != '*')
{
char wild = compare[pW];
if (wild != '?' && wild != str[pS])
return false;
pW++;
pS++;
}
int pSm = 0;
int pWm = 0;
while (pS < lS && pW < lW)
{
char wild = compare[pW];
if (wild == '*')
{
pW++;
if (pW == lW)
return true;
pWm = pW;
pSm = pS + 1;
}
else if (wild == '?' || wild == str[pS])
{
pW++;
pS++;
}
else
{
pW = pWm;
pS = pSm;
pSm++;
}
}
while (pW < lW && compare[pW] == '*')
pW++;
return pW == lW && pS == lS;
}
}