Fix stat/lstat error checking in a few places.

closes #6929. Please review.
Shouldn't this be `err == nil && !fileInfo.IsDir()` ? As in, if there were no errors, then fileInfo is not nil, so we can check IsDir ?