这不是一个真正的编程问题,是否有命令行或Windows工具(Windows 7)来获取文本文件的当前编码?当然,我可以写一个小c#应用程序,但我想知道是否有一些已经内置?


当前回答

(Linux)命令行工具'file'可通过GnuWin32在Windows上使用:

http://gnuwin32.sourceforge.net/packages/file.htm

如果你安装了git,它位于C:\Program Files\git\usr\bin.

例子:

    C:\Users\SH\Downloads\SquareRoot>file *
    _UpgradeReport_Files;         directory
    Debug;                        directory
    duration.h;                   ASCII C++ program text, with CRLF line terminators
    ipch;                         directory
    main.cpp;                     ASCII C program text, with CRLF line terminators
    Precision.txt;                ASCII text, with CRLF line terminators
    Release;                      directory
    Speed.txt;                    ASCII text, with CRLF line terminators
    SquareRoot.sdf;               data
    SquareRoot.sln;               UTF-8 Unicode (with BOM) text, with CRLF line terminators
    SquareRoot.sln.docstates.suo; PCX ver. 2.5 image data
    SquareRoot.suo;               CDF V2 Document, corrupt: Cannot read summary info
    SquareRoot.vcproj;            XML  document text
    SquareRoot.vcxproj;           XML document text
    SquareRoot.vcxproj.filters;   XML document text
    SquareRoot.vcxproj.user;      XML document text
    squarerootmethods.h;          ASCII C program text, with CRLF line terminators
    UpgradeLog.XML;               XML  document text

    C:\Users\SH\Downloads\SquareRoot>file --mime-encoding *
    _UpgradeReport_Files;         binary
    Debug;                        binary
    duration.h;                   us-ascii
    ipch;                         binary
    main.cpp;                     us-ascii
    Precision.txt;                us-ascii
    Release;                      binary
    Speed.txt;                    us-ascii
    SquareRoot.sdf;               binary
    SquareRoot.sln;               utf-8
    SquareRoot.sln.docstates.suo; binary
    SquareRoot.suo;               CDF V2 Document, corrupt: Cannot read summary infobinary
    SquareRoot.vcproj;            us-ascii
    SquareRoot.vcxproj;           utf-8
    SquareRoot.vcxproj.filters;   utf-8
    SquareRoot.vcxproj.user;      utf-8
    squarerootmethods.h;          us-ascii
    UpgradeLog.XML;               us-ascii

其他回答

(Linux)命令行工具'file'可通过GnuWin32在Windows上使用:

http://gnuwin32.sourceforge.net/packages/file.htm

如果你安装了git,它位于C:\Program Files\git\usr\bin.

例子:

    C:\Users\SH\Downloads\SquareRoot>file *
    _UpgradeReport_Files;         directory
    Debug;                        directory
    duration.h;                   ASCII C++ program text, with CRLF line terminators
    ipch;                         directory
    main.cpp;                     ASCII C program text, with CRLF line terminators
    Precision.txt;                ASCII text, with CRLF line terminators
    Release;                      directory
    Speed.txt;                    ASCII text, with CRLF line terminators
    SquareRoot.sdf;               data
    SquareRoot.sln;               UTF-8 Unicode (with BOM) text, with CRLF line terminators
    SquareRoot.sln.docstates.suo; PCX ver. 2.5 image data
    SquareRoot.suo;               CDF V2 Document, corrupt: Cannot read summary info
    SquareRoot.vcproj;            XML  document text
    SquareRoot.vcxproj;           XML document text
    SquareRoot.vcxproj.filters;   XML document text
    SquareRoot.vcxproj.user;      XML document text
    squarerootmethods.h;          ASCII C program text, with CRLF line terminators
    UpgradeLog.XML;               XML  document text

    C:\Users\SH\Downloads\SquareRoot>file --mime-encoding *
    _UpgradeReport_Files;         binary
    Debug;                        binary
    duration.h;                   us-ascii
    ipch;                         binary
    main.cpp;                     us-ascii
    Precision.txt;                us-ascii
    Release;                      binary
    Speed.txt;                    us-ascii
    SquareRoot.sdf;               binary
    SquareRoot.sln;               utf-8
    SquareRoot.sln.docstates.suo; binary
    SquareRoot.suo;               CDF V2 Document, corrupt: Cannot read summary infobinary
    SquareRoot.vcproj;            us-ascii
    SquareRoot.vcxproj;           utf-8
    SquareRoot.vcxproj.filters;   utf-8
    SquareRoot.vcxproj.user;      utf-8
    squarerootmethods.h;          us-ascii
    UpgradeLog.XML;               us-ascii

使用Windows自带的普通记事本打开文件。 当你点击“另存为…”时,它会显示文件的编码。 它看起来是这样的:

无论默认选择的编码是什么,这就是文件的当前编码。 如果它是UTF-8,您可以将其更改为ANSI并单击保存以更改编码(或visa-反之)。

我知道有许多不同类型的编码,但当我被告知我们的导出文件是UTF-8,他们需要ANSI时,这就是我所需要的。这是一个一次性的输出,所以记事本适合我。

供参考:根据我的理解,我认为“Unicode”(如在记事本中列出的)是UTF-16的虚名。 更多关于记事本的“Unicode”选项:Windows 7 - UTF-8和Unicdoe

您可以在文件位置上打开git bash,然后运行命令file -i file_name来检查

例子

user filesData
$ file -i data.csv
data.csv: text/csv; charset=utf-8

安装git(在Windows上你必须使用git bash控制台)。类型:

file --mime-encoding *   

对于当前目录中的所有文件,或

file --mime-encoding */*   

对于所有子目录中的文件

我发现另一个有用的工具是:https://archive.codeplex.com/?p=encodingchecker EXE可以在这里找到