Directory listings from “dir” in Windows in wrong codepage

When trying to output a directory listing using
dir /b /s > files.txt
I had a problem where the accented characters were appearing incorrectly.

The solution (found in this answer on stackoverflow.com) was to change the codepage of the terminal before running the command with
chcp 1252
(in this case it changes it to the Western Europe codepage which is what I needed, other characters may require other codepages).