Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return a collection of files from a given directory in Elixir?

In Ruby, I can use

target_files = Dir["/some/dir/path/*.rb"]
#=> ["/some/dir/path/foo.rb", "/some/dir/path/bar.rb", "/some/dir/path/baz.rb"]

which will return an array of all of the matching files in a directory. How can I do something similar in Elixir?

like image 398
FelixFortis Avatar asked Nov 21 '16 11:11

FelixFortis


1 Answers

You're looking for Path.wildcard/2:

iex(1)> Path.wildcard("/tmp/some/dir/path/*.rb")
["/tmp/some/dir/path/bar.rb", "/tmp/some/dir/path/baz.rb",
 "/tmp/some/dir/path/foo.rb"]
iex(2)> Path.wildcard("/tmp/**/*b*.rb")
["/tmp/some/dir/path/bar.rb", "/tmp/some/dir/path/baz.rb"]
like image 191
Dogbert Avatar answered Oct 29 '22 13:10

Dogbert