use File.directory? instead of Dir.exists?

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