Created
June 11, 2014 15:50
-
-
Save annidy/9264e8a8bb21f4b941a5 to your computer and use it in GitHub Desktop.
文件夹内,数字文件重命名
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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