Sha256: c01db0094d9276782fccb8735515f1b6d2c0bb97effc5ba795273d5b76c6ee4d
Contents?: true
Size: 663 Bytes
Versions: 1
Compression:
Stored size: 663 Bytes
Contents
require 'renumber/version' module Renumber def sorted_files(path) raise ArgumentError, 'path must be a directory' unless File.directory?(path) file_entries_from_path(path).sort end def change_files(path, prefix=nil, suffix=nil) sorted_files = sorted_files(path) return if sorted_files.length == 0 Dir.chdir(path) zeros_length = Math.log10(sorted_files.length).ceil sorted_files.each_with_index do |file, index| File.rename(file, "#{prefix}#{index.to_s.rjust(zeros_length, '0')}#{suffix}") end end private def file_entries_from_path(path) Dir.entries(path).select { |file| File.file?(file) } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
renumber-0.0.2 | lib/renumber.rb |