List of files with different extensions from the directory

How to list specific file extensions in a directory at a time? eg; I just want to list all the files .jpgand .gifthe directory. So I use only files jpeg:

@images = Dir.glob("my/pictures/*.jpg")

how to do this for jpg(s) and gif(s)? Hh

+4
source share
1 answer

Do as below

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

From the documentation {p,q}

Matches literal por literal q. Equivalent to alternating patterns in a regular expression. Corresponding literals can be longer than one character. You can specify more than two literals.

+6
source

Source: https://habr.com/ru/post/1533929/


All Articles