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

**URL:** <https://discourse.julialang.org/t/get-vector-of-filenames-in-directory-matching-regex-but-has-the-language-changed/40480>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [May 30, 2020, 7:39pm UTC](https://discourse.julialang.org/t/get-vector-of-filenames-in-directory-matching-regex-but-has-the-language-changed/40480 "2020-05-30T19:39:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon64288406](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@anon64288406](https://discourse.julialang.org/u/anon64288406)\
**Post date:** [May 30, 2020, 7:39pm UTC](https://discourse.julialang.org/t/get-vector-of-filenames-in-directory-matching-regex-but-has-the-language-changed/40480/1 "2020-05-30T19:39:22Z")

</div>

I want to do something similar to what [this 2017 StackOverflow person](https://stackoverflow.com/q/42522530/8605348) wanted: Get a Vector of all filenames in a directory matching a certain regular expression.

[This answer](https://stackoverflow.com/a/42528317/8605348) says the following was valid:

```julia
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?

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [May 30, 2020, 7:48pm UTC](https://discourse.julialang.org/t/get-vector-of-filenames-in-directory-matching-regex-but-has-the-language-changed/40480/2 "2020-05-30T19:48:51Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![anon64288406](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@anon64288406](https://discourse.julialang.org/u/anon64288406)\
**Post date:** [May 30, 2020, 7:51pm UTC](https://discourse.julialang.org/t/get-vector-of-filenames-in-directory-matching-regex-but-has-the-language-changed/40480/3 "2020-05-30T19:51:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)\
**Post date:** [May 30, 2020, 7:59pm UTC](https://discourse.julialang.org/t/get-vector-of-filenames-in-directory-matching-regex-but-has-the-language-changed/40480/4 "2020-05-30T19:59:47Z")

</div>

FWIW, in Julia 1.5 it will possible to write:

```julia
filter(contains(r"^trip_data"), readdir())

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [May 30, 2020, 8:28pm UTC](https://discourse.julialang.org/t/get-vector-of-filenames-in-directory-matching-regex-but-has-the-language-changed/40480/5 "2020-05-30T20:28:01Z")

</div>

I use [`Glob.jl`](https://github.com/vtjnash/Glob.jl), which provides Posix-compliant filename matching:

```julia
using Glob
readdir(glob"^trip_data", "path/to/directory/")
```

---

<div class="post-metadata">

**Author:** ![anon64288406](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@anon64288406](https://discourse.julialang.org/u/anon64288406)\
**Post date:** [May 30, 2020, 8:30pm UTC](https://discourse.julialang.org/t/get-vector-of-filenames-in-directory-matching-regex-but-has-the-language-changed/40480/6 "2020-05-30T20:30:51Z")

</div>

Glob gets points for having no other package dependencies.
