List files in a directory, meeting certain conditions

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

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

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

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?

Take a look at Glob.jl for one implementation of file globbing.

1 Like

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

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.