Ruby遍历文件夹同时计算文件的md5sum
#!/usr/bin/ruby-w
#
require'digest/md5'
ifARGV.empty?
puts"usgae:#$0path"
exit0
end
dir_name=ARGV.shift
defdir_md5sum(path)
md5s=Array.new
ifFile.directory?(path)
Dir.new(path).eachdo|file|
nextiffile=~/^\.+$/
file="#{path}/#{file}"
ifFile.directory?(file)
dir_md5sum(file)
elsifFile.file?(file)
md5="#{Digest::MD5.hexdigest(File.read(file))}#{file}"
md5s.push(md5)
end
end
elsifFile.file?(path)
md5="#{Digest::MD5.hexdigest(File.read(path))}#{path}"
md5s.push(md5)
else
puts"IvalidFiletype"
exit2
end
md5s.eachdo|item|
putsitem
end
end
dir_md5sum(dir_name)
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短