# remove this line if you want to pass filenames as command line args
ARGV.replace ARGF.each_line(chomp: true).to_a
max_digits = 3
max_path_length = ARGV.each.map(&:length).max
ARGV.each do |path|
# next unless File.file?(path)
ext = File.extname(path)
basename = File.basename(path, ext)
dir = File.dirname(path)
new_base = basename.sub(/([^0-9])(0*[0-9]+)$/) {$1 + $2.rjust(max_digits, "0")}
new_name = new_base + ext
new_path = dir == '.' ? new_name : dir + '/' + new_name
puts sprintf("%-#{max_path_length}s => %s", path, new_path)
end
IyByZW1vdmUgdGhpcyBsaW5lIGlmIHlvdSB3YW50IHRvIHBhc3MgZmlsZW5hbWVzIGFzIGNvbW1hbmQgbGluZSBhcmdzCkFSR1YucmVwbGFjZSBBUkdGLmVhY2hfbGluZShjaG9tcDogdHJ1ZSkudG9fYQoKbWF4X2RpZ2l0cyA9IDMKbWF4X3BhdGhfbGVuZ3RoID0gQVJHVi5lYWNoLm1hcCgmOmxlbmd0aCkubWF4CgpBUkdWLmVhY2ggZG8gfHBhdGh8CiAgICAjIG5leHQgdW5sZXNzIEZpbGUuZmlsZT8ocGF0aCkKICAgIGV4dCA9IEZpbGUuZXh0bmFtZShwYXRoKQogICAgYmFzZW5hbWUgPSBGaWxlLmJhc2VuYW1lKHBhdGgsIGV4dCkKICAgIGRpciA9IEZpbGUuZGlybmFtZShwYXRoKQoKICAgIG5ld19iYXNlID0gYmFzZW5hbWUuc3ViKC8oW14wLTldKSgwKlswLTldKykkLykgeyQxICsgJDIucmp1c3QobWF4X2RpZ2l0cywgIjAiKX0KICAgIG5ld19uYW1lID0gbmV3X2Jhc2UgKyBleHQKICAgIG5ld19wYXRoID0gZGlyID09ICcuJyA/IG5ld19uYW1lIDogZGlyICsgJy8nICsgbmV3X25hbWUKICAgIHB1dHMgc3ByaW50ZigiJS0je21heF9wYXRoX2xlbmd0aH1zID0+ICVzIiwgcGF0aCwgbmV3X3BhdGgpCmVuZA==
Li4veHkwXzAudHh0CmZvby9iYXIveHkwXzAudHh0Cnh5MV8xLnR4dAp4eTFfMDEudHh0Cnh5MV8xMC50eHQKeHkxXzAxMi50eHQKeHkxXzAxMjMudHh0Cnh5MV8wMTIwMy50eHQKeHkxXzAxMjAzMC50eHQKCnh5MV8wMTIuMDMudHh0Cnh5MV8wMTIuMDMuLnR4dAoKeHkxXzAudHh0Cnh5MV8wMC50eHQKeHkxXzAwMC50eHQKeHkxXzAwMDAudHh0Cgp4eTFfMC4xCnh5MV8wMC4wMQp4eTFfMDAwLjAwMAouMAouMQouMDEKLjAwMQouMDAwMA==
../xy0_0.txt
foo/bar/xy0_0.txt
xy1_1.txt
xy1_01.txt
xy1_10.txt
xy1_012.txt
xy1_0123.txt
xy1_01203.txt
xy1_012030.txt
xy1_012.03.txt
xy1_012.03..txt
xy1_0.txt
xy1_00.txt
xy1_000.txt
xy1_0000.txt
xy1_0.1
xy1_00.01
xy1_000.000
.0
.1
.01
.001
.0000