From: Ned Konz Date: 2002-07-27T03:39:08+09:00 Subject: Re: Some basic Ruby questions On Friday 26 July 2002 11:31 am, I wrote: > On Friday 26 July 2002 11:19 am, Benjamin Sommerfeld wrote: > > def pictureMethod > > executeNativeCommand("ls | grep \"jpg\" > pictures.txt") > > pictureFile = File.open("pictures.txt","r") > > while(pictureFile.hasMoreLines) > > array.attach(pictureFile.actualLine) > > pictureFile.goOneLineDown > > end > > end > > Why would you want to call external programs when Ruby does all of > that? > > array = Dir.new('.').entries.grep(/\.jpg$/) Which, as Chris pointed out, is more efficiently written as: array = Dir[ '*.jpg' ] You might also look at the find module if you need to search a hierarchy. To find all the .jpg files in or under the current directory: require 'find' array = [] Find.find('.') { |f| array << f if /\.jpg$/ =~ f } -- Ned Konz http://bike-nomad.com GPG key ID: BEEA7EFE