From: Albert Schlef Date: 2011-03-25T11:18:23+09:00 Subject: Re: Problems moving and renaming pictures with this code, what wrong? Fily Salas wrote in post #988915: > I want to rename them and then move them You can do this in one step. > pic_number = 1 > pic_names.each do |name| > [...] > pic_number = pic_number + 1 > end You can instead do: pic_names.each_with_index do |name, pic_number| [...] end (but pic_number would start at 0.) > new_name = if pic_number < 10 > > "#{batch_name}0#{pic_number}.jpg" > > else > "#{batch_name}#{pic_number}.jpg" > > end You can also do: new_name = "%s%0d2.jpg" % [batch_name, pic_number+1] (I added 1 to pic_number because now it starts at zero.) -- Posted via http://www.ruby-forum.com/.