On Oct 18, 11:22 am, "Robert Klemme" <shortcut... / googlemail.com> wrote: > 2007/10/18, Luis <lcres... / gmail.com>: > > > > > > The typical (and IIRC most efficient) idiom is to pass on the block > > > parameter: > > > > def foo(&b) > > > foo(&b) > > > end > > > That looks nice and simple. > > Thanks! > > > > Another remark: it seems you are reinventing Find.find(). Why do you do > > > that? > > > As I said, the dir scanning was just an example of recursiveness. > > Still, I do need to scan a directory in a way that I get an array of > > files per each block call, and not one file at a time, because I want > > to compare the contents of a directory with other directory, in order > > to identify changed files, new files, deleted files, etc. > > You can still build that with Find.find() which saves you the traversal code: > > #!ruby > > require 'find' > require 'pp' > > ARGV.each do |dir| > list = Hash.new {|h,k| h[k] = []} > > Find.find dir do |f| > d, b = File.split f > next if /^\.\.?$/ =~ b > list[d] << b > end > > pp list > end > > Cheers > > robert Cool! The code is much more advanced compared with mine... yes, I am a Ruby beginner. Still, if I understood your code well, it creates a whole directory tree in memory, which, if applied to "/" (or "c:\") it can really take a huge amount of RAM. I want to process the list of files in each directory, one directory at a time, and then forget about these files once they are processed. However I guess I can modify your code above a bit, remove the hash, check that "d" is the same as the previous pass, and if not yield the list, etc. Regards, Luis.