Skip to content

Instantly share code, notes, and snippets.

@cisolarix
Created March 2, 2014 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cisolarix/9300717 to your computer and use it in GitHub Desktop.
Save cisolarix/9300717 to your computer and use it in GitHub Desktop.
incrementing numbers in all files within a directory
require 'find'
require 'fileutils'
Find.find(ENV["HOME"] + "/Movies/backup") do |path|
if FileTest.file? path
if path =~ /(\d+)/
old_num = $1
new_num = old_num.to_i + 1
new_path = path.gsub( old_num, new_num.to_s )
puts "renaming #{path} to #{new_path}\n"
FileUtils.mv(path, new_path)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment