Module: FileCrawler::Finder::Command::Search

Includes:
Base
Included in:
FileCrawler::Finder
Defined in:
lib/file_crawler/finder/command/search.rb

Instance Method Summary collapse

Methods included from Base

#exec

Instance Method Details

#search(path, options = {}) ⇒ Object



6
7
8
9
10
# File 'lib/file_crawler/finder/command/search.rb', line 6

def search(path, options={})
  tap {
    @files = search_directories(path, options)
  }
end

#search_directories(path, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/file_crawler/finder/command/search.rb', line 12

def search_directories(path, options={})
  result = []
  cmd = "find #{path} -type d"
  if options[:maxdepth] && options[:maxdepth] > 0
    cmd = "find #{path} -maxdepth #{options[:maxdepth]} -type d"
  end

  exec(cmd).each_line {|item|
    item.chomp!
    valid = true
    if options[:exclude_invisible_file]
      filename = File.basename(item)
      valid = !filename.start_with?('.')
    end
    result << item if valid
  }

  result
end