Skip to content

Instantly share code, notes, and snippets.

@EnriqueVidal
Created January 24, 2013 06:47
Show Gist options
  • Save EnriqueVidal/4618174 to your computer and use it in GitHub Desktop.
Save EnriqueVidal/4618174 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
ARGV.each_with_index do |file, index|
next unless File.exists?( file )
filename_arr = File.basename( file ).split '_'
# Make sure to add a couple of seconds
new_version = Time.now.strftime( '%Y%m%d%H%M%S' ).to_i + index
# Change the version
filename_arr[0] = new_version
new_name = filename_arr.join '_'
new_file = File.join File.dirname( file ), new_name
# Rename in filesystem
FileUtils.mv file, new_file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment