Class: FileCheckHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/duplicate_file_check.rb

Instance Method Summary collapse

Constructor Details

#initializeFileCheckHelper

desc “Instance”



8
9
# File 'lib/duplicate_file_check.rb', line 8

def initialize()  
end

Instance Method Details

#check(type, suffix) ⇒ Object

duplicate file check



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/duplicate_file_check.rb', line 12

def check(type, suffix)
	# specify files which should not be copied
       current_dir = Dir.pwd
       puts "🐈 #{current_dir}"
       fileNames = []
       files = Dir[current_dir + "/**/*.{#{suffix}}"]
       files.each do |old_dest| 
           fileNames.push(File.basename(old_dest))
       end
       fileMaps = Hash.new([])
       files.each { |filePath| 
           key = ""
           if type == "md5" 
               key = md5 = Digest::MD5.hexdigest(File.read(filePath))
           elsif type == "name"
               key = File.basename(filePath)
           end
           fileArr = [] + fileMaps[key] 
           fileMaps[key] = fileArr.push(filePath)
       } 
       fileMaps.each {|key, value|
           if value.count > 1
               puts "#{key} repeat count: #{value.count}"
               fileArr = [] + value
               fileArr.each { |filePath|
                   puts "#{filePath}"
               }
           end
       }
end