Sha256: 8fd911d024a3641ac76e8580e0e51edc53d758282dcc020549acb239cf7b55ee
Contents?: true
Size: 1.39 KB
Versions: 16
Compression:
Stored size: 1.39 KB
Contents
#-- # Credit due to George Moschovitis <gm@navel.gr> #++ class Dir # Recursively scan a directory and pass each file # to the given block. 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 class << self # Alias for Dir#ls_r alias_method( :recurse, :ls_r ) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # # TODO This test needs good Dir mockup. =begin #no test yet require 'test/unit' class TCDir < Test::Unit::TestCase def test_ls_r td = Dir.pwd Dir.chdir $TESTDIR r = ["A", "A/B","A/B/C.txt", "A/B.txt", "A.txt"].collect{ |e| File.join( 'ls_r', e ) } fs = Dir.ls_r( 'ls_r' ) assert_equal( r, fs, Dir.pwd ) Dir.chdir td end def test_recurse td = Dir.pwd Dir.chdir $TESTDIR r = ["A", "A/B","A/B/C.txt", "A/B.txt", "A.txt"].collect{ |e| File.join( 'ls_r', e ) } fs = Dir.recurse( 'ls_r' ) assert_equal( r, fs, Dir.pwd ) Dir.chdir td end end =end
Version data entries
16 entries across 16 versions & 1 rubygems