opts.num_digits = 2
opts.extension = nil
opts.starting_number = 1
+ opts.prefix_counter_increment = 1
$fu_args = { :verbose => true }
opts.preserve_names = false
"Specify the glob expression to use. Example: '*/*.mp3'.") do |d|
opts.glob = d
end
+ myparser.on("--prefix-counter-increment NUMBER", "-I",
+ "The increment to use (defaults to 1)") do |e|
+ opts.prefix_counter_increment = e.to_i
+ end
end
parser.parse!(args)
end
def rename_files(file)
- dst="#{get_file_name($opts.starting_number + $total_files)}.#{$opts.extension}"
+ dst="#{get_file_name($prefix_counter)}.#{$opts.extension}"
if (file != dst) then
FileUtils.mv(file, dst, $fu_args)
end
- $total_files = $total_files + 1
+ $prefix_counter = $prefix_counter + $opts.prefix_counter_increment
end
def rename_files_keep_names(file)
else
raise "can't find proper name for #{file}"
end
- full_name = "#{get_file_name(1 + $total_files)} - #{proper_file}"
+ full_name = "#{get_file_name($prefix_counter)} - #{proper_file}"
FileUtils.mv(file, full_name, $fu_args)
- $total_files = $total_files + 1
+ $prefix_counter = $prefix_counter + $opts.prefix_counter_increment
end
# MAIN
end
# rename files
-$total_files = 0
+$prefix_counter = $opts.starting_number
if ( $opts.preserve_names ) then
file_iter { |f| rename_files_keep_names(f) }
else