[Gambas-user] Find files without extensions using LIKE

Tobias Boege taboege at gmail.com
Tue Oct 17 23:11:07 CEST 2017


On Tue, 17 Oct 2017, Benoît Minisini wrote:
> Le 17/10/2017 à 22:28, Moviga Technologies a écrit :
> > Hi!
> > 
> > Is it possible to get all files without extensions using Dir()?
> > 
> > This does not work: *[^.]*
> > 
> > 
> 
> Of course, as the "*" will match any point in the file name.
> 
> The native regexp syntax cannot express that, you have to filter the result
> of Dir() "by hand".
> 
> As Dir() takes an integer option, I can add a new option that tells to
> return files that -do not- match the pattern. That way you will be able to
> do something like:
> 
> Dir(Directory, "*.*", gb.InvertMatch)
> 
> But I don't really like that solution.
> 
> The better would be enhancing the regexp syntax, but it's almost impossible
> without breaking backward-compatibility.
> 
> Not simple...
> 

Gambas has something that looks like built-in PCRE with the MATCH keyword.
You could leave LIKE alone until Gambas 4 by introducing a gb.Match flag,
which replaces the invocation of LIKE by MATCH. This looks like a sound
way to handle it: both are matching operators, the faster one is the default
but you can choose the more powerful one if you need it. In this case,
the new flag is much more versatile than a gb.InvertMatch, if that's why
you didn't like it.

There are other places where this constant could be used, for example the
Mode argument to String[].Find(), which already understands gb.Like.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk



More information about the User mailing list