Search for files in a folder

julia

Solution

An alternative solution is to use the Glob.jl package. For example, if you have the following list of files in your directory:

foo1.txt
foo2.txt
foo3.txt
bar1.txt
foo.jl

and you want to find all text files starting with "foo" you would write

using Glob
glob("foo*.txt") #if searching the working directory
#output:
#"foo1.txt"
#"foo2.txt"
#"foo3.txt"
glob("foo*.txt","path/to/dir") #for specifying a different directory
#output:
#"path/to/dir/foo1.txt"
#"path/to/dir/foo2.txt"
#"path/to/dir/foo3.txt"

Problem

I'm trying parse a lot of text files using Julia, and I want to loop across an array of file names instead of typing out a function call to read each of them individually. So far I have been unable to find a way to search a folder for files matching a pattern. Is there a base library Julia function that will return all file names in a given folder, matching a given string pattern? The equivalent function in R would be `list.files()`, if that helps communicate what I want.

Original source