Reputation: 21618
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.
Upvotes: 7
Views: 1625
Reputation: 118271
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.
Upvotes: 10