Get Vector of filenames in directory matching regex. But has the language changed?

I want to do something similar to what this 2017 StackOverflow person wanted: Get a Vector of all filenames in a directory matching a certain regular expression.

This answer says the following was valid:

filter(r"^trip_data", readdir())

But now, in a Julia 1.4.2 REPL with no packages loaded, this throws: # MethodError: objects of type Regex are not callable. So how would I do it now?

I guess there are simpler versions exists, but this one works

filter(x -> occursin(r"^trip_data", x), readdir())

That’s the one I came up with. Which is fine. Was just wondering if a simpler way exists.

FWIW, in Julia 1.5 it will possible to write:

filter(contains(r"^trip_data"), readdir())
3 Likes

I use Glob.jl, which provides Posix-compliant filename matching:

using Glob
readdir(glob"^trip_data", "path/to/directory/")
4 Likes

Glob gets points for having no other package dependencies.