From: Roy Zuo Date: 2011-05-08T08:42:58+09:00 Subject: Re: Threading Loops It is very convenient to use Thread in Ruby, but maybe you should first get rid of pic_numb self-increment statements. pic_names.collect.with_index do |name, pic_numb| Thread.new do print ' . ' new_name = batch_name + pic_numb.to_s + ' .jpg' File.rename name, new_name end end.each{ |thread| thread.join } Roy On Sun, May 08, 2011 at 08:20:07AM +0900, Bobby S. wrote: > I understood how to thread functions, but I don't understand how to > implement it outside of that. I am trying to make a picture re-namer and > I want to thread the renaming part to speed it up. > > > pic_names = Dir["{E://**/*.{JPG, jpg}"] > pic_numb = 1; > batch_name = "test" > > #Want to thread this part. > pic_names.each do |name| > print ' . ' > new_name = batch_name + pic_numb.to_s + ' .jpg' > File.rename name, new_name > pic_numb += 1 > end > > Thanks in advance. > > -- > Posted via http://www.ruby-forum.com/. > --