Ruby tip of the day

Posted by phillip Tue, 28 Feb 2006 19:31:00 GMT

EDIT (11.11.2007): Dir#glob (aliased as: Dir[]) could also be used.

find all files in a directory matching some pattern

list = Dir.new('.').entries.select { |f| f =~ /_\d{2}.(jpg|gif)$/ }
=> ["11-029_42.jpg", "1209-180_32.jpg", "1210-180_32.jpg", "1218-180_32.jpg"]

list.size
=> 4

Posted in , | Tags