Try to open the file before use data from stat.

Looks like on mingw we get bogus last modification times on directories.
Should fix the mingw bots.