Created
October 15, 2008 15:37
This file contains 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
#!/usr/bin/env ruby | |
# | |
# Author: Anil Wadghule | |
# | |
# FRenamer: Renames image files for passed command line parameters | |
# Usage: frenamer . "the_dark_knight" | |
# It renames image files in current directory with names like the_dark_knight_1.jpg, the_dark_knight_2.jpg ... | |
# | |
# Installation: | |
# Copy it to your /usr/bin or any directory which is in your PATH | |
# chomod 777 it, to make it executable | |
# | |
# | |
Dir.chdir(ARGV[0]) | |
cnt = 1 | |
Dir["*"].each do |filename| | |
puts "renaming" | |
regex = /(?:.*)\.(png|jpg|gif)$/i | |
fname = ARGV[1] || "picture" | |
suffix = "#{fname}_#{cnt}" | |
new_filename = filename.gsub(regex, "#{suffix}.\\1") | |
puts new_filename | |
File.rename(filename, new_filename) | |
cnt += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment