Ruby遍历文件夹同时计算文件的md5sum
Ruby遍历文件夹同时计算文件的md5sum
发布时间:2016-12-28 来源:查字典编辑
摘要:#!/usr/bin/ruby-w#require'digest/md5'ifARGV.empty"usgae:#$0path"exit0e...

#!/usr/bin/ruby -w # require 'digest/md5' if ARGV.empty"usgae: #$0 path" exit 0 end dir_name=ARGV.shift def dir_md5sum(path) md5s=Array.new if File.directory?(path) Dir.new(path).each do |file| next if file =~ /^.+$/ file="#{path}/#{file}" if File.directory?(file) dir_md5sum(file) elsif File.file?(file) md5="#{Digest::MD5.hexdigest(File.read(file))} #{file}" md5s.push(md5) end end elsif File.file?(path) md5="#{Digest::MD5.hexdigest(File.read(path))} #{path}" md5s.push(md5) else puts "Ivalid File type" exit 2 end md5s.each do |item| puts item end end dir_md5sum(dir_name)

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ruby专题学习
热门ruby专题学习
脚本专栏子分类