From: Mariano Kamp Date: 2006-06-05T23:55:59+09:00 Subject: Re: Directory.entries problems with while loops 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 > > Hi Tait, did you look at Dir.glob (http://corelib.rubyonrails.org/classes/Dir.html#M000865)? I guess that would solve your problem in one line of code. Can't really tell without seeing test data, but I guess you could get rid of the infinite loop symptom by checking for <= instead of < in your loop or you can get rid of the cause by removing the first "counter+=1" line. It will be incremented anyway. Btw. there are better loop constructs with built-in counters, but for your case I would go with Dir.glob and forget about traversing the directories by hand. Cheers, Mariano