# Pathname::Pathname (Class)

In: | pathname.rb
Parent: | Object

mixed

## Methods

delete find foreach mkpath rmtree unlink

## Public Instance methods

find(&block) {|Pathname.new(f.sub(%r{\A\./}, '')) }| ...}

Pathname#find is a iterator to traverse directory tree in depth first manner. It yields a pathname for each file under the directory which is pointed by self.

Since it is implemented by find.rb, Find.prune can be used to control the traverse.

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

[Source]

    # File pathname.rb, line 477
      def find(&block)
        require 'find'
        if @path == '.'
          Find.find(@path) {|f| yield Pathname.new(f.sub(%{\A\./}, '')) }
        else
          Find.find(@path) {|f| yield Pathname.new(f) }
        end
      end

mkpath()

[Source]

    # File pathname.rb, line 489
      def mkpath
        require 'fileutils'
        FileUtils.mkpath(@path)
        nil
      end

rmtree()

[Source]

    # File pathname.rb, line 495
      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

unlink()

[Source]

    # File pathname.rb, line 506
      def unlink()
        if FileTest.directory? @path
          Dir.unlink @path
        else
          File.unlink @path
        end
      end

delete()

Alias for unlink

foreach(*args, &block)

This method is obsoleted at 1.8.1.

[Source]

    # File pathname.rb, line 517
      def foreach(*args, &block) # compatibility to 1.8.0.  obsoleted.

        warn "Pathname#foreach is obsoleted.  Use each_line or each_entry."
        if FileTest.directory? @path
          # For polymorphism between Dir.foreach and IO.foreach,

          # Pathname#foreach doesn't yield Pathname object.

          Dir.foreach(@path, *args, &block)
        else
          IO.foreach(@path, *args, &block)
        end
      end

[Validate]