I'm trying to iterate through a directory of image files and rename them. Each time I run this method it will rename one file and delete the rest. I also used File.rename.
require 'fileutils'
def rename_image_files
@last_product = Product.find(:last).id + 1
Dir.foreach("app/assets/images/products/#{@last_product}").each do |item|
@count = 0
@count += 1
new_name = "#{@last_product.to_s << '_'}#{@count}"
@item = item
unless @item == '.' or @item == '..'
FileUtils.mv("app/assets/images/products/#{@last_product}/#{@item}", "app/assets/images/products/#{@last_product}/#{new_name}.png")
end
end