[Gambas-user] Exist with wildcard
Tobias Boege
tobs at taboege.de
Wed Aug 4 12:45:56 CEST 2021
On Wed, 04 Aug 2021, bb wrote:
> I am trying to determine if a particular library has been installed in
> a particular diectory.
>
> I was sure Exist(path) took wildcards into account, but it doen't seem
> so. Any ideas on how to do a wildcard search for a file then?
>
> e.g. I am looking for "ph.internals:*.gambas" in "/srv/gbshared/lib".
> The actual file is "ph.internals:1.0.gambas" i.e. it has the library
> version included in it, but I don't know WHAT version I am looking for.
>
Exist() doesn't understand wildcards, but Dir() does, but not with the
same syntax as the shell, but with Gambas's LIKE syntax. You can use
If Dir("/srv/gbshared/lib", "ph.internals:*.gambas", gb.File).Count > 0 Then
...
This does not short-circuit to returning True as soon as a file matching
the pattern is found, but always gives you the entire array of all matches
before you call Count on it, but probably that's not a critical overhead.
Best,
Tobias
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list