Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Win32 API to do wildcard string match

I am looking for a wildcard string match API (not regex match). I cannot use anything other than Win32 APIs.

like image 705
user15071 Avatar asked Jul 31 '09 21:07

user15071


2 Answers

There is PathMatchSpec - but handling is specialized for files, so results might not be what you expect if you need general wildcard matching.

Otherwise, you should probably go with an RegEx, as Pavel detailed.

[edit] I incorrectly assumed PathMatchSpec shares the properties of FindFirstFile/FindNextFile. I've ran a few tests - it doesn't. So it looks like the best candidate.

like image 151
peterchen Avatar answered Sep 19 '22 08:09

peterchen


Strange that so many years passed and nobody gave you this answer:

There is a WIN32 API that does exactly what you're looking for. (I found it searching in the MSDN for "wildcard")

It's name is SymMatchString(). It sits in DbgHelp.dll which is part of the operating system.

Put a CriticalSection around the API call if your app is mulithreaded!

http://msdn.microsoft.com/en-us/library/windows/desktop/ms681355%28v=vs.85%29.aspx

The API that FindFirstFile() uses internally for wildcard matches is probably FsRtlIsNameInExpression().

Elmü

like image 27
Elmue Avatar answered Sep 19 '22 08:09

Elmue