473,388 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Windows-style pattern matching

Hi all, quick question. Is there a Windows function I can call to compare a
single string like "HELLO.TXT" to a Windows filename/path pattern (possibly
with wildcards) like "H?LL?.*" ? Basically I want to pattern match using
Windows' rules but on a string I pass in as opposed to going through
FindFirstFile, et al.

If not, does anyone know where I can find such a function already
implemented online?

Finally if not that, does anyone know where I can find a list of the
specific rules that Windows uses to pattern match in the FindFirstFile
function?

Thanks
Oct 5 '06 #1
5 1825
Mike C# wrote:
Hi all, quick question. Is there a Windows function I can call to
compare a single string like "HELLO.TXT" to a Windows filename/path
pattern (possibly with wildcards) like "H?LL?.*" ? Basically I want
to pattern match using Windows' rules but on a string I pass in as
opposed to going through FindFirstFile, et al.
No, there is no such function exposed in the public API.
>
If not, does anyone know where I can find such a function already
implemented online?
I haven't seen one. The rules are complex and subtle (beyond your worst
nightmares).
>
Finally if not that, does anyone know where I can find a list of the
specific rules that Windows uses to pattern match in the FindFirstFile
function?
I posed the exact rules to microsoft.public.win32.programmer.kernel a couple
years back...

http://groups.google.com/group/micro...UTF-8&c2coff=1

-cd
Oct 5 '06 #2

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:eh****************@TK2MSFTNGP03.phx.gbl...
Mike C# wrote:

No, there is no such function exposed in the public API.
I was afraid of that. Oh well, I found a couple of really basic functions
online that perform similarly (though not exactly), and should be good
enough for my needs. I'm not really doing anything extravagant, just some
really basic wildcard-style filename matches like "H?LLO.*" and "A*.*" type
stuff.

Thanks.
Oct 5 '06 #3
"Mike C#" <xy*@xyz.comwrote in message
news:OZ**************@TK2MSFTNGP02.phx.gbl...
>
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:eh****************@TK2MSFTNGP03.phx.gbl...
>Mike C# wrote:

No, there is no such function exposed in the public API.

I was afraid of that. Oh well, I found a couple of really basic functions
online that perform similarly (though not exactly), and should be good
enough for my needs. I'm not really doing anything extravagant, just some
really basic wildcard-style filename matches like "H?LLO.*" and "A*.*"
type stuff.

Thanks.
That's commonly called "globbing", if you need another term to feed Google.

Also, the filename pattern matching is pretty dumb insofar as you can't have
'*' midstring. So it wouldn't be hard to write a test function.
Split both filename and pattern at the (last) '.'. Walk through the base
(file title), declaring success upon hitting a '*' in the pattern, and
failure if the characters don't match and the pattern isn't '?'. When you
reach the end-of-string start over with the extension.
Oct 10 '06 #4
On Tue, 10 Oct 2006 14:32:05 -0500, "Ben Voigt" <rb*@nospam.nospamwrote:
>Also, the filename pattern matching is pretty dumb insofar as you can't have
'*' midstring.
I think that was true for DOS, but Windows (>= Win32) handles it OK.

--
Doug Harrison
Visual C++ MVP
Oct 10 '06 #5
"Doug Harrison [MVP]" <ds*@mvps.orgwrote in message
news:b6********************************@4ax.com...
On Tue, 10 Oct 2006 14:32:05 -0500, "Ben Voigt" <rb*@nospam.nospamwrote:
>>Also, the filename pattern matching is pretty dumb insofar as you can't
have
'*' midstring.

I think that was true for DOS, but Windows (>= Win32) handles it OK.
Absolutely correct. File specifications with * and ? mid-string have been
fully supported since NT 3.1 more than 10 years ago.

-cd
Oct 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
7
by: Tyler Foreman | last post by:
Hello, I have a strange problem that occurs every so often in my application. It usually takes place when I hide one form and activate another. What happens is I get the following exception:...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
1
by: freesteel | last post by:
I have posted about this problem before. SInce then I found a much better article to help with embedding python in a multithreaded application: http://www.linuxjournal.com/article/3641 I...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.