# Directory lstat mass listing

**URL:** <https://www.ruby-forum.com/t/directory-lstat-mass-listing/111135>\
**Category:** Ruby\
**Created:** [August 2, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/directory-lstat-mass-listing/111135 "2007-08-02T23:06:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [August 2, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/directory-lstat-mass-listing/111135/1 "2007-08-02T23:06:09Z")

</div>

Been trying to get a full list of file sizes out of a directory  
structure, starting from ‘/’ … The code below wont work because the  
method doesnt accept wildcards, and instead gives the size of the  
directory block rather than the file sizes within it.

Dir.chdir(’/’)

File.size(" **/**").each {|x| puts x}

and the problem with File.size("/.") is that it list the size of the  
directory  
block size ‘4096’

i was thinking that somehow i could run a directory surf with the  
Find.find method  
— Find.find("/", “./”) {|path| puts path} —  
and shove that data into an array, then run File.size on each array item  
with a range… anyone have any ideas?  
-Thanks

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [August 2, 2007, 11:41pm UTC](https://www.ruby-forum.com/t/directory-lstat-mass-listing/111135/2 "2007-08-02T23:41:28Z")

</div>

On Aug 2, 3:06 pm, Jon H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> directory  
> block size ‘4096’
> 
> ## i was thinking that somehow i could run a directory surf with the Find.find method — Find.find(“/”, “./”) {|path| puts path} — and shove that data into an array, then run File.size on each array item with a range… anyone have any ideas? -Thanks
> 
> Posted viahttp://www.ruby-forum.com/.

Here’s some code to help get you further:

def crawl(current\_dir)  
Dir.entries(current\_dir).each do |entry|  
if File.directory?(entry)  
crawl(entry)  
else  
puts File.size(entry)  
end  
end  
end

Note that this code cut-and-pasted will not work. For example, make  
sure you don’t visit “.” and “…” or you will be in an infinite loop.  
Ask again if you still need more assistance.

Matt W.

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [August 2, 2007, 11:42pm UTC](https://www.ruby-forum.com/t/directory-lstat-mass-listing/111135/3 "2007-08-02T23:42:28Z")

</div>

2007/8/2, Jon H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

I can suggest this:

Dir.glob( “\*\*/\*”).each{ |f| puts File.size( f) if File.file?( f)}

Regards,  
Raf
