Double check whether the parent directory really exists using stat()

Fixes #7760