use File.directory? instead of Dir.exists?

Dir.exists? was introduced in ruby 1.9, but MacOSX 10.7 has ruby 1.8.7.