Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list files with different extensions from a directory

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.

like image 821
tokhi Avatar asked Mar 28 '14 14:03

tokhi


1 Answers

Do as below

@images = Dir.glob("my/pictures/*.{jpg,gif}")

From documentation of {p,q}

Matches either literal p or literal q. Equivalent to pattern alternation in regexp. Matching literals may be more than one character in length. More than two literals may be specified.

like image 106
Arup Rakshit Avatar answered Oct 07 '22 09:10

Arup Rakshit