Safer way to check if a path is a file

Directories can contain `.` too.