Methods
Public Class methods
Is a path parental to another?
[ show source ]
# File lib/facets/core/dir/self/ancestor.rb, line 8 def self.ancestor?(parent_path, child_path) %r|^#{Regexp.escape(parent_path)}| =~ child_path end
Ascend a directory path.
[ show source ]
# File lib/facets/core/dir/self/ascend.rb, line 6 def self.ascend( dir, inclusive=true, &blk) dir = dir.dup blk.call( dir ) if inclusive ri = dir.rindex('/') while ri dir = dir.slice(0...ri) if dir == "" blk.call( '/' ) ; break end blk.call( dir ) ri = dir.rindex('/') end end
[ show source ]
# File lib/facets/core/dir/self/descend.rb, line 4 def self.descend( path ) #:yield: paths = path.split('/') paths.size.times do |n| yield File.join( *paths[0..n] ) end end
Recursively scan a directory and pass each file to the given block.
[ show source ]
# File lib/facets/core/dir/self/ls_r.rb, line 8 def self.ls_r(path='.', &block) list = [] stoplist = ['.', '..'] Dir.foreach(path) do |f| next if stoplist.include?(f) filename = path + '/' + f list << filename block.call(filename) if block if FileTest.directory?(filename) and not FileTest.symlink?(filename) list.concat( Dir.recurse(filename, &block) ) end end list end