Correctly check if a path is a directory. Fix by Brian Korver.