当前位置:首页 >> 脚本专栏

Ruby遍历文件夹同时计算文件的md5sum

#!/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}/#{file}"
            if File.directory"#{Digest::MD5.hexdigest(File.read(file))} #{file}"
                md5s.push(md5)
            end
        end
    elsif File.file"#{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)