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