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
Lookup directory tree for a path.
TODO: Make a non class method version of this?
Returns full path or `nil` if not found. [String,nil]
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('.') 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.