# List files in a directory, meeting certain conditions

**URL:** <https://discourse.julialang.org/t/list-files-in-a-directory-meeting-certain-conditions/103197>\
**Category:** General Usage\
**Tags:** filesystem\
**Created:** [August 25, 2023, 4:59pm UTC](https://discourse.julialang.org/t/list-files-in-a-directory-meeting-certain-conditions/103197 "2023-08-25T16:59:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [August 25, 2023, 4:59pm UTC](https://discourse.julialang.org/t/list-files-in-a-directory-meeting-certain-conditions/103197/1 "2023-08-25T16:59:57Z")

</div>

In MATLAB, I can list all the files in a directory like this:

```matlab
f = dir('/Users/myname/path'); 

```

and I can limit results to the files that meet certain conditions like this:

```matlab
f = dir('/Users/myname/path/StartsWith*.txt'); 

```

which would return all the filenames in the directory that start with the string `StartsWith` and has the extension `.txt`.

In Julia, I am aware of the `readdir` function, but it doesn’t seem to allow wildcards or limiting to certain filetypes. Is there an easy way to accomplish this?

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [August 25, 2023, 5:24pm UTC](https://discourse.julialang.org/t/list-files-in-a-directory-meeting-certain-conditions/103197/2 "2023-08-25T17:24:29Z")

</div>

Take a look at [Glob.jl](https://docs.juliahub.com/General/Glob/stable/) for one implementation of file globbing.

---

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [August 25, 2023, 5:50pm UTC](https://discourse.julialang.org/t/list-files-in-a-directory-meeting-certain-conditions/103197/3 "2023-08-25T17:50:40Z")

</div>

Thanks @devel-chm. Following your suggestion, I found that the solution is:

```julia
using Glob

f = glob("StartsWith*.txt", "/Users/myname/path")

```

which returns all the filenames in the folder `/Users/myname/path` that begin with `StartsWith` and have the extension `.txt`.
