Windows – How to pipe Windows “dir” in ANSI codepage

ansicommand linedirwindows

This applies to both Windows XP and Windows 7.

Some of my files have names with European characters, for example the German a-umlaut, also known as a-diaeresis.

These are displayed correctly in Windows Explorer, and also in a command shell (cmd.exe) window in response to the "dir" command.

However, if that "dir" command is directed to a file, e.g.

dir > file.txt

then the European characters in that file are represented in a DOS codepage; for example the a-umlaut is represented as decimal 132 (hex 0x84). This is not what I want. I want the file to be in the ANSI codepage, where for example a-umlaut is decimal 228 (hex 0xE4).

Issuing the command "cmd /?" results in help information including the line

/A      Causes the output of internal commands to a pipe or file to be ANSI

This sounds like exactly what I want. However, either the sequence of commands

cmd /A
dir > file.txt
exit

or the equivalent single command line

cmd /A /C dir > file.txt

produces exactly the same file.txt as before; with its Europoean characters still in the DOS code page.

So my question is, how can I get "dir" to write a file in the ANSI codepage?

  • Rich

Best Answer

I think there is easy way, "from the box"

chcp 1252
dir > file.txt
Related Question