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 好听的元旦简短祝福语