chcp 65001 and a .bat file

前端 未结 6 593
小鲜肉
小鲜肉 2021-02-08 10:59

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         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-08 11:54

    Tested on Windows 7 only, may not work on Windows Vista.

    Apparently chcp doesn't affect dir directly.

    Parse the output of dir and print it via echo:

    chcp 65001
    >list_of_files.txt (for /f "delims=" %%a in ('dir /B /O:N') do echo %%a)
    

    Note: the output file won't have UTF-8 Byte Order Mark.

提交回复
热议问题