-
-
Save deathwishdave/53562c3d9417893e6cc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'find' | |
require 'pathname' | |
class SharedFile | |
attr_reader :file_name | |
attr_reader :file_size | |
def initialize(path, file_size) | |
#@path = path | |
@file_name = Pathname.new(path).basename | |
@file_size = file_size | |
end | |
def ==(other) | |
self.file_name == other.file_name && self.file_size == other.file_size | |
end | |
def eql?(other) | |
self == other | |
end | |
def hash | |
[file_name, file_size].hash | |
end | |
end | |
files = [] | |
Find.find(".") do |path| | |
files << SharedFile.new(path,File.size(path)) #if path =~ /.*\.pdf$/ | |
end | |
results = files.group_by{|file| file}.map{|k,v| [k,v.count] } | |
# puts results[1].inspect | |
results.each do |result| | |
puts "#{result[0].file_name}, #{result[0].file_size}, #{result[1]}" if result[1] > 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment