Do not re-encode / to # if / is a platform separator, and correctly handle permission errors (Fixes #831)