Use stat() instead of opendir() for checking existence of a dir

opendir() fails if given path doesn't have read permissions for
the current user.