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 婶婶拜年祝福语大全简短