Class | Dir
In: | lib/core/facets/dir/ascend.rb lib/core/facets/dir/each_child.rb lib/core/facets/dir/multiglob.rb lib/core/facets/dir/parent.rb lib/core/facets/dir/recurse.rb
Parent: | Object

### Methods

ascend descend each_child ls_r multiglob multiglob_r parent? recurse

### Public Class methods

ascend(dir, inclusive=true, &blk)

Ascend a directory path.

      a = []

      Dir.ascend("/var/log") do |path|
        a << path
      end

      a  #=> ['/var/log', '/var', '/']

CREDIT: Daniel Berger, Jeffrey Schwab

TODO: make it work with windows too use FileTest.root?

descend(path) {|| ...}

Descend a directory path.

      d = []

      Dir.descend("/var/log") do |path|
        d << path
      end

      d  #=> ['/', '/var', '/var/log']

CREDIT: Daniel Berger, Jeffrey Schwab

ls_r(path='.', &block)

Same as Dir#recurse.

multiglob(*patterns)

Like `glob` but can take multiple patterns.

      Dir.multiglob('tmp/*.rb', 'tmp/*.py')

Rather then constants for options multiglob accepts a trailing options hash of symbol keys…

      :noescape    File::FNM_NOESCAPE
      :casefold    File::FNM_CASEFOLD
      :pathname    File::FNM_PATHNAME
      :dotmatch    File::FNM_DOTMATCH
      :strict      File::FNM_PATHNAME && File::FNM_DOTMATCH

It also has an option for recurse…

      :recurse     Recurively include contents of directories.

For example

      Dir.multiglob('tmp/*', :recurse => true)

would have the same result as

      Dir.multiglob('tmp/**/*')

multiglob_r(*patterns)

The same as `multiglob`, but recusively includes directories.

      Dir.multiglob_r('tmp')

is equivalent to

      Dir.multiglob('tmp', :recurse=>true)

The effect of which is

      Dir.multiglob('tmp', 'tmp/**/**')

parent?(parent_path, child_path)

Is a path parental to another?

      Dir.parent?('parent', 'parent/child')  #=> true

TODO: Needs improvement.

TODO: Instance version?

recurse(path='.', &block)

Recursively scan a directory and pass each file to the given block.

      Dir.recurse('.') 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.

### Public Instance methods

each_child(*ignore) {|file unless ignore.any?{ |i| i === file| ...}

Like each, except the "." and ".." special files are ignored. You can use `ignore` to override ’.’ and ’..’ and ignore other entries via a exact match or regular expression.

CREDIT: Tyler Rick

[Validate]