Add .exists() check before isDirectory()

The IllegalArgumentException should only be thrown when the File
object exists but is not a directory type.