Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment