Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Under Win7 cmd.exe, running the following commands will reproduce the situation I faced today:

(to clarify, my D: partition is formatted as NTFS.)

D:\...\_play\notes> chcp
Active code page: 65001

D:\...\_play\notes>dir /b
输入.txt
输出.txt

D:\...\_play\notes> chcp 936
活动代码页: 936                 (the chinese version of "Active Code Page: 936")

D:\...\_play\notes>dir /b
输入.txt
输出.txt

This is the behavior of dir command, and when compared with type command, it looks even more confusing.

D:\...\_play\notes>chcp
活动代码页: 936                 (the chinese version of "Active Code Page: 936")

D:\...\_play\notes>type 输入.txt
====== 璺ㄧ晫鍙傝€冭祫婧愪俊鎭緭鍏ュ獟浠?=====   (text garbled as the file is encoded in utf8)

D:\...\_play\notes> chcp 65001
Active code page: 65001

D:\...\_play\notes>type 输入.txt
====== 跨界参考资源信息输入媒介 ======
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Filenames are stored as UTF-16LE in NTFS and VFAT, and the file functions know how to convert this to the current CP (if possible). File contents are read as bytes, and so appear garbled under anything but their appropriate CP.

share|improve this answer
    
Thanks for clarify the underlying difference between them. –  PIM Geek Jul 5 '13 at 3:33
    
Adding a BOM to the beginning of the file can help. -- Whoops, I meant to revise this before sending, as it just came in to my mind, that Notepad actually does that when saving. –  Adam L. S. Jan 28 at 8:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.