From: Pete Yandell Date: 2006-06-06T10:12:35+09:00 Subject: Re: Directory.entries problems with while loops I've got to say, this is the least Ruby-ish Ruby I've ever seen! Someone has already pointed out Dir.glob, and that's probably the best approach, but even assuming you don't have that you can do: array = Dir.entries(File.dirname("directory.rb")).grep(/tlb/) Even if, for some strange reason, you needed to write the loop yourself, you could simplify it to: array = [] direc.each do |file| array << file if file =~ /tlb/ end Ruby has a lot of powerful methods for operations on Arrays. You should have a good read through the docs for Array and Enumerable! Pete Yandell http://9cays.com/ On 06/06/2006, at 12:33 AM, Tait Pollard wrote: > unknown wrote: >> On Jun 5, 2006, at 8:57 AM, Tait Pollard wrote: >> Show us some code and then we can help. >> >> cr > > here is the code > > c=File.dirname("directory.rb") > direc=Dir.entries(c) > b= Regexp.new(/tlb/) > counter,counter1=0,0 > array=[] > while(counter if (direc[counter]=~b) > puts direc[counter] > array[counter1]=direc[counter] > counter=+1 > end > counter=+1 > end > > > -- > Posted via http://www.ruby-forum.com/. >