Hi --

On Tue, 14 Aug 2007, Bertram Scharpf wrote:

> Hi,
>
> Am Dienstag, 14. Aug 2007, 21:58:17 +0900 schrieb John Joyce:
>> You might want to use something like this:
>>
>> def dir_empty?(path_to_dir)
>>   Dir.chdir(path_to_dir)
>>   if Dir.glob('*').length > 0
>>    return false
>>   else
>>    return true
>> end
>
> What's this?
>
>  1.  'end' is missing.
>  2.  'if ... then false else true end' is a lot of hot air
>      around 'not ...'.
>  3.  As a side effect the method changes the current
>      directory.
>
> Say
>
>  def dir_empty? path_to_dir
>    Dir.chdir path_to_dir do
>      not Dir.glob('*').length > 0
>    end
>  end

How about:

   def dir_empty?(path_to_dir)
     Dir.glob("#{path_to_dir}/*").empty?
   end

> Then, you may consider hidden files ...
>
> First think, then write. Sorry!

Please leave the snideness and nastiness out of it. They add nothing
but snideness and nastiness.


David

-- 
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)