#!/usr/bin/env ruby # # timestamp.rb - rename files according to the timestamp # # Copyright:: (C) 2006 Toshiaki Katayama # License:: The Ruby License # Website:: http://kumamushi.org/~k/resize/ # Version:: 1.0 # if ARGV[0] =~ /^[-+]\d+/ hours = ARGV.shift.to_i else hours = 0 end ARGV.each do |file| next unless File.file?(file) dir = File.dirname(file) sfx = File.basename(file).split('.').last.downcase next unless /jpg|jpeg|mpg|mpeg|wmv|avi|thm|mov/.match(sfx) mtime = File.mtime(file) + hours * 60 * 60 time = mtime.strftime("%Y-%m%d-%H%M-%S") count = 0 while File.exist?("#{dir}/#{time}#{sprintf("%02d",count)}.#{sfx}") count += 1 end newfile = "#{dir}/#{time}#{sprintf("%02d",count)}.#{sfx}" puts "Moving #{file} -> #{newfile}" File.rename(file, newfile) end