# Rdir: search recursive for files with a given name pattern

**URL:** <https://discourse.julialang.org/t/rdir-search-recursive-for-files-with-a-given-name-pattern/75605>\
**Category:** New to Julia\
**Tags:** question, filesystem\
**Created:** [February 1, 2022, 9:23pm UTC](https://discourse.julialang.org/t/rdir-search-recursive-for-files-with-a-given-name-pattern/75605 "2022-02-01T21:23:19Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 1, 2022, 10:55pm UTC](https://discourse.julialang.org/t/rdir-search-recursive-for-files-with-a-given-name-pattern/75605/12 "2022-02-01T22:55:29Z")

</div>

You could use the Glob package with `walkdir`, for example:

```julia
import Glob
function rdir(dir::AbstractString, pat::Glob.FilenameMatch)
    result = String[]
    for (root, dirs, files) in walkdir(dir)
        append!(result, filter!(f -> occursin(pat, f), joinpath.(root, files)))
    end
    return result
end
rdir(dir::AbstractString, pat::AbstractString) = rdir(dir, Glob.FilenameMatch(pat))

```

Then do e.g. `rdir("somedir", "*.jl")`.

---

_[View the full topic](https://discourse.julialang.org/t/rdir-search-recursive-for-files-with-a-given-name-pattern/75605)._
