Use stat() output for directory and file tests (fix #391)