Class: Grizzled::Directory

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

Overview

Useful directory-related methods.

Class Method Summary collapse

Class Method Details

.walk(dirname, &block) ⇒ Object

Walk a directory tree, starting at dirname, invoking the supplied block on each directory. The block is passed a Dir object. The directory is walked top-down, not depth-first. To terminate the traversal, the block should return false. Anything else (including nil) continues the traversal.

Parameters:

dirname

The name (path) of the directory to walk.

block

The block to invoke on each entry.



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/grizzled/dir.rb', line 77

def self.walk(dirname, &block)
  if block.call(Dir.new(dirname)) != false
    Dir.entries(dirname).each do |entry|
      path = File.join(dirname, entry)
      if File.directory?(path) && (entry != '..') && (entry != '.')
        Grizzled::Directory.walk(path, &block)
      end
    end
  end
  nil
end