我在欧洲的Windows cmd.exe上运行这个代码,我使用这里的本地设置,用于我的语言。所以我在目录的名称中使用变音符号。
I run this code on Windows cmd.exe in Europe and I use local settings here, for my language. So I use diacritics in names of the directories.
我尝试列出目录的名称,并正确显示。然后我把它保存到文件中,但是当我在记事本中打开它时,变音符号是不可读的,例如,而不是StředníČechy我有Stýedn ¬echy。
I try to list names of the directories and they are displayed correctly. Then I save them into file, but when I open it in notepad, the diacritics is not readable: for example, instead of Střední Čechy I have Stýednˇ ¬echy.
我做错了什么,如何更正?
What did I do wrong and how can I correct it?
@echo off del directories.conf FOR /F "delims=!" %%R IN ('dir * /b /a:d /o:n') DO ( IF EXIST "%%R\scenery" ( echo %%R echo %%R >> directories.conf ) ELSE (ECHO NOT INCLUDED %%R) ) Echo Directory list created... pause推荐答案
尝试使用/ u启动cmd.exe开关。这将导致cmd以UTF-16写入。
Try starting cmd.exe with /u switch. That will cause cmd to write in UTF-16.
还需要使用 chcp 1250切换到代码页1250(中欧的ANSI) 。
您可以在批处理脚本中执行此操作。我为你做了一个结构是:
You can do it inside your batch script. I made one for you. The structure is:
.\Jižní Morava .\Jižní Morava\scenery .\Pelhřimov .\Pelhřimov\scenery .\Nic moc výlet .\Střední Čechy .\Střední Čechy\scenery脚本:
@echo off if _%1_==_main_ ( call :main ) else ( cmd /u /c "%0 main" ) goto :eof :main chcp 1250 del directories.conf for /F "delims=!" %%R in ('dir * /b /a:d /o:n') do ( if exist %%R\scenery ( echo %%R echo %%R >> directories.conf ) else ( echo not included: %%R ) ) echo Directory list created... pause goto :eof此外,我建议您阅读 andrewdotn的伟大答案相关问题。
Also I recommend you to read andrewdotn's great answer to a related question.
更多推荐
将`dir`输出重定向到文件后,编码不正确
发布评论