[Mono-list] Pattern Matching to Find Files

Jonathan Gilbert 2a5gjx302 at sneakemail.com
Thu Jan 5 22:52:15 EST 2006

At 5:06 PM 03/01/2006 -0500, Abe Gillespie wrote:
> I'd like to use Directory.GetFiles() to get all the files that don't
> HAVE an extension.  Is there a pattern I can send into GetFiles()
> that'll do the trick?  ... I guess the pattern needs to match when
> there is NO dot.

At 05:03 PM 05/01/2006 -0500, Abe Gillespie wrote:
>Thanks for the help Jon.  Unfortunately I *do* need a cross platform
>solution.  Any other ideas?

There is no cross-platform API that can do what you want. The only thing
you can do is request all files and then manually ignore the ones which
have a non-trailing dot. You can use a regular expression within .NET to do
this; see System.Text.RegularExpressions.

A regular expression which matches any filename in which all dots, if there
are any, are trailing, is:

string regex_pattern = @"^[^\.]*\.*$";

Basically, there is no cross-platform OS-level API that does the kind of
filtering you want, so even if .NET offered it as part of its class
library, it would be retrieving the full list of filenames anyway, so you
wouldn't save much, if anything :-)

Good luck,

Jonathan Gilbert

More information about the Mono-list mailing list