# Getting a list of file names

**URL:** <https://discourse.julialang.org/t/getting-a-list-of-file-names/39492>\
**Category:** New to Julia\
**Tags:** matlab\
**Created:** [May 14, 2020, 8:59pm UTC](https://discourse.julialang.org/t/getting-a-list-of-file-names/39492 "2020-05-14T20:59:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eslb82](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@eslb82](https://discourse.julialang.org/u/eslb82)\
**Post date:** [May 14, 2020, 8:59pm UTC](https://discourse.julialang.org/t/getting-a-list-of-file-names/39492/1 "2020-05-14T20:59:05Z")

</div>

I’ve been asked to convert some code from Matlab to Julia, and I am stuck right at the beginning with some Regex issues

I want the equivalent of

file\_name = dir(‘A\*.mmode’)  
file\_name = {file\_name.name}

In Matlab, this will make me a matrix of however many files with the appropriate start and end bits.

I saw the following code to search for files:

searchdir(path,key) = filter(x-\>occursin(key,x), readdir(path))

But when I run

julia\> file\_name = searchdir(pwd(),^(A.+iq.mmode)$)  
ERROR: syntax: invalid identifier name “.”

Any suggestions?

---

<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 14, 2020, 9:03pm UTC](https://discourse.julialang.org/t/getting-a-list-of-file-names/39492/2 "2020-05-14T21:03:31Z")

</div>

Try [Glob.jl](https://github.com/vtjnash/Glob.jl), which implements POSIX-compliant filename matching.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [May 14, 2020, 9:17pm UTC](https://discourse.julialang.org/t/getting-a-list-of-file-names/39492/3 "2020-05-14T21:17:14Z")

</div>

yous `readdir()` and perform regex on that list of strings.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 14, 2020, 9:23pm UTC](https://discourse.julialang.org/t/getting-a-list-of-file-names/39492/4 "2020-05-14T21:23:19Z")

</div>

I can maybe be wrong but did you put the regex inside a string? In Julia regexes are strings prefixed by `r`, [see the relevant section of the manual](https://docs.julialang.org/en/v1/manual/strings/#Regular-Expressions-1).

---

<div class="post-metadata">

**Author:** ![eslb82](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@eslb82](https://discourse.julialang.org/u/eslb82)\
**Post date:** [May 15, 2020, 11:26am UTC](https://discourse.julialang.org/t/getting-a-list-of-file-names/39492/5 "2020-05-15T11:26:28Z")

</div>

Thank you!!  
file\_name = searchdir(pwd(),r"^(A.+iq.mmode)$") worked.
