Created
March 2, 2014 01:51
-
-
Save cisolarix/9300717 to your computer and use it in GitHub Desktop.
incrementing numbers in all files within a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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