10MB 이상의 파일중에서 중복된 파일 찾기
# -*- coding: cp949 -*- require 'find' require 'digest/md5' file_list = Array.new Find.find("C:\\") do |path| if File.file?(path) and File.size(path) > 10_000_000 # digest = Digest::MD5.hexdigest(File.read(path)) # --> 위와 같이 해도 되지만, 메모리를 많이 잡아먹는다. digest = Digest::MD5.file(path).hexdigest file_list << digest+"|"+path end end distinct_list = Hash.new(0) file_list.each do |val| (md5, file) = val.split(/\|/) distinct_list[md5] += 1 end distinct_list.each do |md5, count| if count >= 2 print "\n["+md5+"]\n" file_list.each do |val| (md5_2, file) = val.split(/\|/) if md5 == md5_2 print file+"\n" end end end end
댓글 없음:
댓글 쓰기