Fixed valid directory checking, which failed on paths to files