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)
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短