Sha256: bafe66c83fde050b63130641b8fa26f067e9479b32c1bfb9c87c5d0b0c87e0eb

Contents?: true

Size: 843 Bytes

Versions: 5

Compression:

Stored size: 843 Bytes

Contents

#! /usr/bin/ruby -w
# coding: utf-8

# 拡張子は保存
# -i オプションで開始番号を指定
# -p : preserve old name 元のファイル名を残す。foo.txt -> 001-foo.txt
require "filerenamer/commander.rb"
require "filerenamer/optionparser.rb"


OPTIONS = {}
op = FileRenamer::OptionParser.new
op.on("-i num", "--initial", "Indicate initial number."){ |val|
  OPTIONS[:init] = val.to_i
}
op.on("-p", "--preserve", "Preserve old name."){
  OPTIONS[:preserve] = true
}
op.parse!(ARGV)

OPTIONS[:init] ||= 0

fr = FileRenamer::Commander.new(op.options, ARGV)
fr.execute do |filename|
  @counter ||= OPTIONS[:init]
  if (OPTIONS[:preserve])
    new_name = sprintf("%03d-%s", @counter, filename)
  else 
    extention = File.extname(filename)
    new_name = sprintf("%03d%s", @counter, extention)
  end
  @counter += 1
  new_name
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
filerenamer-0.0.7 bin/rennum
filerenamer-0.0.6 bin/rennum
filerenamer-0.0.5 bin/rennum
filerenamer-0.0.4 bin/rennum
filerenamer-0.0.3 bin/rennum