From: John Joyce Date: 2007-03-10T18:10:16+09:00 Subject: Re: Find.find --- returns directories/files backwards You could also use a system call to the tools "which" or "locate" or "find" on *nix systems and pipe that to where you need it. Very DRY! On Mar 10, 2007, at 4:44 PM, Morton Goldberg wrote: > On Mar 9, 2007, at 7:35 PM, Brad wrote: > >> New user question: >> >> It seems to me when I run: >> Find.find('/user/name/documents') {|path| puts path} >> >> it returns all the directories in the reverse order. I was expecting >> the directories to be returned in alphabetical order, but that >> doesn't >> seem to be the case. Also, in one case it reads half of a >> directory's >> files, then the sub dirs and then it finished reading the rest of the >> directory it started in and finished writing them in the Puts >> statement. >> >> Am I missing something? How do you do get it to write out the >> directories in alphabetical order? >> >> Any and all help welcome. > > That's just the way Fine.find works. My experience is that, for > most applications, the order in which Find.find traverses > directories doesn't cause problems. But it may not be the best way > to get a deep list of the contents of a directory. Two alternatives > you might try are > > BASE = '/Users/mg/Downloads' > > paths = [] > Find.find(BASE) { |path| paths << path } > puts paths.reverse > > or > > Dir.glob("#{BASE}/**/*") { |path| puts path } > > Note: this form of Dir.glob doesn't find dotted (hidden) files and > Fine.find does (there is a flag you can set to get dotted files > with Dir.glob). > > Regards, Morton >