Sha256: 32ae2dfd54240149df5424f99bf8ccc96507e17bd4d0f4f55687135d3ffaaa6c

Contents?: true

Size: 785 Bytes

Versions: 6

Compression:

Stored size: 785 Bytes

Contents

# frozen_string_literal: true

# Traverse a directory tree looking for files with a specific extension
class FileSieve
  attr_reader :found_files

  def initialize(directory, extension)
    @found_files = []
    @extension = extension
    @search_directory = directory
    sieve(directory)
  end

  # Recursively search the directory tree for files with @extension
  def sieve(directory)
    de_dot(Dir.entries(directory)).each { |file|
      search = File.absolute_path(directory + File::SEPARATOR + file)
      if File.directory?(search)
        sieve(search)
      elsif file.match?(@extension)
        @found_files.push(search)
      end
    }
  end

  # Clean away . and .. from the directory list
  def de_dot(list)
    list.delete('.')
    list.delete('..')
    list
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
aws-spec-etl-0.1.5 lib/file_sieve.rb
aws-spec-etl-0.1.4 lib/file_sieve.rb
aws-spec-etl-0.1.3 lib/file_sieve.rb
aws-spec-etl-0.1.2 lib/file_sieve.rb
aws-spec-etl-0.1.1 lib/file_sieve.rb
aws-spec-etl-0.1.0 lib/file_sieve.rb