Class: LsAll::LsAll

Inherits:
Object
  • Object
show all
Defined in:
lib/ls_all/ls_all.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_depth = 0, count = false) ⇒ LsAll

Returns a new instance of LsAll.



6
7
8
9
# File 'lib/ls_all/ls_all.rb', line 6

def initialize( max_depth=0, count=false )
   @max_depth = max_depth
   @count     = count
end

Instance Method Details

#file_count(path) ⇒ Object



44
45
46
47
# File 'lib/ls_all/ls_all.rb', line 44

def file_count( path )
   recursive_files = Dir.glob(path + '/*')
   recursive_files.size.to_s
end

#list_files(files, spacer = '', path = '.', depth = 1) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ls_all/ls_all.rb', line 11

def list_files( files, spacer='', path='.', depth=1)
   path = File.expand_path( path )

   files.each do |f|
      if File.directory?( f )
         
         file_string= f + '/'
         if  (not @max_depth == 0) and (depth == @max_depth) and (@count == true)
            puts spacer + file_string.ljust(20) + ' Count: ' + file_count( f )
         else
            puts spacer + file_string   
         end


         recursive_path=File.expand_path( f )
         Dir.chdir( recursive_path )
         recursive_files = Dir.glob('*')
         recursive_spacer = spacer + ' '

         if (@max_depth == 0) or (depth < @max_depth)
            rec_depth=depth+1 
            list_files(recursive_files, recursive_spacer, recursive_path, rec_depth)
         else
            #
         end
      else
         puts spacer + f
      end
      Dir.chdir( path )
   end

end