#!/usr/bin/env ruby # print a non-existing path variant by appending numeric suffixes. def get_unique_path(path, suffix=nil) suffix ||= "" cand = "#{path}#{suffix}" return cand unless File.exist?(cand) i = 1 loop do cand = "#{path}.#{i.to_s(32)}#{suffix}" return cand unless File.exist?(cand) i += 1 end end ARGV.each { |p| puts get_unique_path(p, suffix) }