class Pathname::Pathname

Public Instance Methods

find(ignore_error: true) { |pathname| ... } click to toggle source

Iterates over the directory tree in a depth first manner, yielding a Pathname for each file under “this” directory.

Returns an Enumerator if no block is given.

Since it is implemented by the standard library module Find, Find#prune can be used to control the traversal.

If self is ., yielded pathnames begin with a filename in the current directory, not ./.

See Find#find

# File ext/pathname/lib/pathname.rb, line 559
def find(ignore_error: true) # :yield: pathname
  return to_enum(__method__, ignore_error: ignore_error) unless block_given?
  require 'find'
  if @path == '.'
    Find.find(@path, ignore_error: ignore_error) {|f| yield self.class.new(f.sub(%r{\A\./}, '')) }
  else
    Find.find(@path, ignore_error: ignore_error) {|f| yield self.class.new(f) }
  end
end
mkpath() click to toggle source

Creates a full path, including any intermediate directories that don't yet exist.

See FileUtils.mkpath and FileUtils#mkdir_p

# File ext/pathname/lib/pathname.rb, line 576
def mkpath
  require 'fileutils'
  FileUtils.mkpath(@path)
  nil
end
rmtree() click to toggle source

Recursively deletes a directory, including all directories beneath it.

See FileUtils#rm_r

# File ext/pathname/lib/pathname.rb, line 585
def rmtree
  # The name "rmtree" is borrowed from File::Path of Perl.
  # File::Path provides "mkpath" and "rmtree".
  require 'fileutils'
  FileUtils.rm_r(@path)
  nil
end