Fix some UTF-8 issues on Windows.

This fixes #9418 and #9618, and potential problems related to directory walking.