Sha256: 990d5182650c465ed53cd98e4bab30eb82c927ab6cf64c627116c1662e51d42e

Contents?: true

Size: 717 Bytes

Versions: 8

Compression:

Stored size: 717 Bytes

Contents

# -*- coding: utf-8 -*-
require 'ostruct'

cwd = File.expand_path( File.join( File.dirname(__FILE__), "..", "..", "lib" ) )
$:.unshift(cwd) unless $:.include?(cwd)
require 'treevisitor'

#
# Find directories without subdirectories
#
class DirWithoutSubDir < TreeRb::BasicTreeNodeVisitor

  def initialize
    super
    @stack = []
    @nr = 0
  end

  def enter_node( pathname )
    @nr += 1
    info = OpenStruct.new(:nr => @nr, :pathname => pathname)
    @stack.push( info )
  end

  def exit_node( pathname )
    info = @stack.pop
    if info.nr == @nr
      puts "leaf: #{pathname}"
    end
  end

end

dtw = TreeRb::DirTreeWalker.new( ".." )
dtw.ignore /^\./
dtw.visit_file=false
dtw.run( DirWithoutSubDir.new )

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tree.rb-0.3.8 examples/directory_walker/directory_without_subdirectory.rb
tree.rb-0.3.7 examples/directory_walker/directory_without_subdirectory.rb
tree.rb-0.3.6 examples/directory_walker/directory_without_subdirectory.rb
tree.rb-0.3.5 examples/directory_walker/directory_without_subdirectory.rb
tree.rb-0.3.4 examples/directory_walker/directory_without_subdirectory.rb
tree.rb-0.3.3 examples/directory_walker/directory_without_subdirectory.rb
tree.rb-0.3.2 examples/directory_walker/directory_without_subdirectory.rb
tree.rb-0.3.1 examples/directory_walker/directory_without_subdirectory.rb