----- Original Message ----- From: "michael libby" <x / ichimunki.com> To: "ruby-talk ML" <ruby-talk / ruby-lang.org> Sent: Sunday, September 22, 2002 10:37 PM Subject: Re: Getting a directory tree > The same problem David has below. The routine doesn't handle recursive > directories well-- it follows the link back up the tree. You know that odd > case where some malcontent has done: > > ln -s ../.. link_up > > In fact, I was surprised my test with David's routine below ever returned, > but believe me... it was the ugliest nested list you ever saw. <grin /> I fixed David's problem just by doing a flatten... the reason it returned a nested list was that he was doing temp + temp.map{...} to which I added a flatten. The case below I think is unrelated. No, I'm not handling symlinks (though I should). Haven't tested this app on UNIX lately. And no symlinks on Windows. :) > > > 2. How would you write this in a reasonably > > > efficient way? > > Add a check for symlinks. > > > def getdirs_d1(root) > return [] if File.lstat(root).symlink? > > > dirs=Dir.entries(root) - [".", ".."] > > temp = dirs.map {|d| root+SEP+d}.select {|d| test(?d,d)} > > temp + temp.map {|x| getdirs1(x) } > > end Thanks, Hal