I have a problem with chcp 65001
command in Windows shell.
I need to generate a list of files in a folder. So I ran cmd.exe, typed
cd folder
dir /B /O:N > list_of_files.txt
It worked, but I had a problem with special, non-ASCII characters which are in some file names.
So I added
chcp 65001
Everything worked, but when I put these commands into a .bat file, the script doesn't work.
So
cd folder
chcp 65001
dir /B /O:N > list_of_files.txt
doesn't generate the list.
and
cd folder
chcp 65001 && dir /B /O:N > list_of_files.txt
as well as
cd folder
chcp 65001 > nul && dir /B /O:N > list_of_files.txt
generates the list, but with the default encoding :/.
Everything works in cmd.exe, but not in .bat files.
I've read the topic: stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called, but it didn't help.
EDIT:
I partially solved my problem, changing chcp 65001
to chcp 1250
because all characters were in this encoding. But actually this doesn't answer the question.