From: Erik Hollensbe Date: 2007-06-12T17:55:49+09:00 Subject: Re: Newb Wants to Better His File, Dir code On 2007-06-08 20:55:42 -0700, rio4ruby said: >>> dirs = Dir.entries(".").reject{|e| /\.{1,2}/ =~ e}.find_all{|e| >>> File.directory? e} >> >>> At this point you have a list of directory names. You can do whatever >>> you like to that list using .each(), .inject(), .collect(), etc. >> >> The above has a small bug: it rejects all hidden directories. If you >> want to block only ".." and ".", then change it to: >> >> dirs = Dir.entries(".").reject{|e| /\.{1,2}$/ =~ e}.find_all{|e| >> File.directory? e} > > This also has bug if you have a file name 'abc.' > > Use rio. Wouldn't changing the regex to read /^\.{1,2}$/ fix this problem? Seems like a lot of unnecessary effort to complicate this code up with an extra library to fix a regular expression. -Erik