0

I have a directory with a file with some unusual characters in its name, a simple dir command returns the correct filename:

> dir /b
ćłńó.txt

I have a very simple for loop running in a command prompt. However, for some reason the for loop is returning a filename with similar but different characters:

> for /f "delims=" %F in ('dir /b') do echo %F
clnó.txt

Obviously this is not the desired result.

How do I fix this?

hedgehog90
  • 1,142
  • 16
  • 31
  • 1
    I think is related to the code page `chcp`. Take a look at this it probably can help you: https://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using. – SNR Sep 26 '19 at 14:53
  • ah, so the answer is to simply use `chcp 65001` before running the command? – hedgehog90 Sep 26 '19 at 15:13
  • Not sure, I cannot reproduce the error. The best I can recommend is to try it out. Also take a look on https://ss64.com/nt/chcp.html to be sure there are no side effects. – SNR Sep 26 '19 at 15:17
  • Does it work using `chcp 65001`? – SNR Sep 26 '19 at 15:21

0 Answers0