class Grizzled::Directory

Useful directory-related methods.

Public Class Methods

walk(dirname, &block) click to toggle source

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.

# 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