Use isdir or isfile instead of exists.