Class: FileCheckHelper

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

Overview

puts “hello cyan”.cyan puts “hello red”.red puts “hello green”.green puts “hello yellow”.yellow puts “hello blue”.blue puts “hello magenta”.magenta puts “hello brown”.brown puts “hello blanchedalmond”.blanchedalmond

Instance Method Summary collapse

Constructor Details

#initializeFileCheckHelper

desc “Instance”



20
21
# File 'lib/duplicate_file_check.rb', line 20

def initialize()  
end

Instance Method Details

#check(type, suffix) ⇒ Object

duplicate file check



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/duplicate_file_check.rb', line 24

def check(type, suffix)
    # specify files which should not be copied
    current_dir = Dir.pwd
    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}".yellow
            fileArr = [] + value
            fileArr.each { |filePath|
                puts "#{filePath}"
            }
        end
    }
end