Guest User

Untitled

a guest
Feb 20th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. #
  3. # Author: Anil Wadghule
  4. #
  5. # FRenamer: Renames image files for passed command line parameters
  6. # Usage: frenamer . "the_dark_knight"
  7. # It renames image files in current directory with names like the_dark_knight_1.jpg, the_dark_knight_2.jpg ...
  8. #
  9. # Installation:
  10. # Copy it to your /usr/bin or any directory which is in your PATH
  11. # chomod 777 it, to make it executable
  12. #
  13. #
  14.  
  15. Dir.chdir(ARGV[0])
  16. cnt = 1
  17. Dir["*"].each do |filename|
  18. puts "renaming"
  19. regex = /(?:.*)\.(png|jpg|gif)$/i
  20. fname = ARGV[1] || "picture"
  21. suffix = "#{fname}_#{cnt}"
  22. new_filename = filename.gsub(regex, "#{suffix}.\\1")
  23. puts new_filename
  24. File.rename(filename, new_filename)
  25. cnt += 1
  26. end
Add Comment
Please, Sign In to add comment