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 |
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 a directory path.
d = [] Dir.descend("/var/log") do |path| d << path end d #=> ['/', '/var', '/var/log']
CREDIT: Daniel Berger, Jeffrey Schwab
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/**/*')
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/**/**')
Is a path parental to another?
Dir.parent?('parent', 'parent/child') #=> true
TODO: Needs improvement.
TODO: Instance version?
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.