wildcards
-
Hi all, I need an algorith to wildcard match two strings similar to what happens when you do a dir *.* - I`d require it to support both * and ? - nothing too fancy !! Appreciate any help in this !! Thanks in advance !! Rajiv
-
Hi all, I need an algorith to wildcard match two strings similar to what happens when you do a dir *.* - I`d require it to support both * and ? - nothing too fancy !! Appreciate any help in this !! Thanks in advance !! Rajiv
Hi, this code should do the trick. It's an adapted function from SysInternals' FileMon application. Regards, Gertjan Schuurmans Amsterdam //--------------------------------------------------- // MatchWildCard // //Parameters // LPCTSTR pszWildCard // LPCTSTR pszFileName // //Returns // BOOL // //Remarks // // MatchWildCard tests whether the given filename matches the wildcard. pszWildCard // can contain * and ? special characters. // BOOL MatchWildCard(LPCTSTR pszWildCard, LPCTSTR pszFileName) { #define UpCase(ch) ((ch) >= 'a' && (ch) <= 'z' ? (ch) - 'a' + 'A' : (ch)) TCHAR chFile, chWild; // End of pattern? if (!*pszWildCard) { return FALSE; } // If we hit a wild card, do recursion if (*pszWildCard == '*') { pszWildCard++; while (*pszFileName && *pszWildCard) { chFile = UpCase(*pszFileName); chWild = UpCase(*pszWildCard); // See if this substring matches if (chWild == chFile || chFile == '*') { if (MatchWildCard(pszWildCard + 1, pszFileName + 1)) { return TRUE; } } // Try the next substring pszFileName++; } // See if match condition was met return (*pszWildCard == 0 || *pszWildCard == '*'); } // Do straight compare until we hit a wild card while (*pszFileName && *pszWildCard != '*') { chFile = UpCase(*pszFileName); chWild = UpCase(*pszWildCard); if (chWild == chFile || chWild == '?') { pszWildCard++; pszFileName++; } else { return FALSE; } } // If not done, recurse if (*pszFileName) { return MatchWildCard(pszWildCard, pszFileName); } // Make sure its a match return (*WildCard == 0 || *WildCard == '*'); ================== The original message was: Hi all,
I need an algorith to wildcard match two strings similar to what happens when you do a dir *.* - I`d require it to support both * and ? - nothing too fancy !!Appreciate any help in this !!
Thanks in advance !!Rajiv