Sha256: 9e241cb202fa80d7676bdd19ee2014da851cb736679efc69bf95c3bb0cf13436

Contents?: true

Size: 837 Bytes

Versions: 3

Compression:

Stored size: 837 Bytes

Contents

class Dir

  # Recursively scan a directory and pass each file to the given block.
  #
  #   Dir.recurse('tmp') do |path|
  #     # ...
  #   end
  #
  # CREDIT: George Moschovitis
  #
  # TODO: If fully compatible, reimplement as alias of Find.find,
  # or just copy and paste Find.find code here if it looks more robust.
  #
  def self.recurse(path='.', &block)
    list = []
    stoplist = ['.', '..']
    Dir.foreach(path) do |f|
      next if stoplist.include?(f)
      filename = (path == '.' ? f : path + '/' + f)
      list << filename
      block.call(filename) if block
      if FileTest.directory?(filename) and not FileTest.symlink?(filename)
        list.concat(Dir.recurse(filename, &block))
      end
    end
    list
  end

  # Same as Dir#recurse.
  def self.ls_r(path='.', &block)
    recurse(path, &block)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-2.9.0 lib/core/facets/dir/recurse.rb
facets-2.9.0.pre.2 lib/core/facets/dir/recurse.rb
facets-2.9.0.pre.1 lib/core/facets/dir/recurse.rb