How to list specific file extensions in a directory in one go? e.g; I just want to list all .jpg
and .gif
files from a directory.
This is how I do for only jpeg
files:
@images = Dir.glob("my/pictures/*.jpg")
how to do this for both jpg
(s) and gif
(s)? tnx.
Do as below
@images = Dir.glob("my/pictures/*.{jpg,gif}")
From documentation of {p,q}
Matches either literal
p
or literalq
. Equivalent to pattern alternation in regexp. Matching literals may be more than one character in length. More than two literals may be specified.
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