module Search

Collection of methods for searching directories.

Public Class Methods

find_all(files_of_type,dir,excluding=[]) { |path| ... } click to toggle source

Searches a directory and it's child directories for all the files whose names match the specified regular expression.

# File lib/shed/search.rb, line 14
def self.find_all(files_of_type,dir,excluding=[])

  Find.find(dir) do |path|
    if FileTest.directory?(path)

      if excluding.include?(File.basename(path))
        Find.prune
      else
        next
      end

    elsif File.extname(path) =~ files_of_type
      yield path
    end
  end
end
for_empties(dir,excluding=[]) { |path| ... } click to toggle source

Scans the path and its children for empty directories.

# File lib/shed/search.rb, line 34
def self.for_empties(dir,excluding=[])

  Find.find(dir) do |path|

    if FileTest.directory?(path)
      if excluding.include?(File.basename(path))
        Find.prune
      else
        # Any dir that only contains ., .., and .svn or .git are empty.
        yield path if Dir.entries(path).join =~ /^\.\.\.(\.(svn|git))?$/
      end
    end
  end
end