[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Directory lstat mass listing

Michael Linfield

8/2/2007 9:06:00 PM

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
--
Posted via http://www.ruby-....

1 Answer

Matt White

8/2/2007 9:39:00 PM

0

On Aug 2, 3:06 pm, Jon Hawkins <globyy3...@hotmail.com> wrote:
> 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
> --
> Posted viahttp://www.ruby-....

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 White