batch-filetextutf-8windows-10ansi

How to simply list all files of a folder using dir to text with UTF-8 encoding?


Simple question:

On Windows 10, I found a quick and dirty solution to save the names of all the files in a folder by just simply:

But, the text file this creates is in ANSI encoding, and thus won't show certain characters... Is there a simple script I can add to the bat file before running it to make the generated texts encoded as UTF-8?


Solution

  • You should add this command chcp 65001 before dir command to change code page to UTF-8

    @echo off
    CHCP 65001>nul
    dir>1.txt
    

    Further reading about CHCP command