Skip to content

Instantly share code, notes, and snippets.

@annidy
Created June 11, 2014 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save annidy/9264e8a8bb21f4b941a5 to your computer and use it in GitHub Desktop.
Save annidy/9264e8a8bb21f4b941a5 to your computer and use it in GitHub Desktop.
文件夹内,数字文件重命名
#!/bin/ruby
# annidy 2014-6-11
d = Dir.new(".")
max = 0
d.each {|x|
m = /^\d+\./.match(x)
m = m or ["0"]
max = [max, m.to_s.to_i].max
}
mx = max.to_s.length
print("Max = ", max)
puts
d.each {|x|
m = /^\d+\./.match(x)
if m
l = mx - m.to_s.length + 1
if l > 0
File.rename(x, "0" * l + x)
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment