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?
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"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With