#! /usr/bin/env ruby # coding: utf-8 require "filerenamer.rb" #require "filerenamer/commander.rb" #require "filerenamer/optionparser.rb" OPTIONS = {} op = FileRenamer::OptionParser.new op.on("-g", "--global", "Global substitution."){ OPTIONS[:global] = true } op.on("-r", "--reg-exp", "Regular expression."){ OPTIONS[:regexp] = true } op.parse!(ARGV) old_str = ARGV.shift new_str = ARGV.shift old_str = /#{old_str}/ if OPTIONS[:regexp] fr = FileRenamer::Commander.new(op.options, ARGV) fr.execute do |filename| if OPTIONS[:global] new_name = filename.gsub(old_str, new_str) else new_name = filename.sub(old_str, new_str) end new_name end