这不是一个真正的编程问题,是否有命令行或Windows工具(Windows 7)来获取文本文件的当前编码?当然,我可以写一个小c#应用程序,但我想知道是否有一些已经内置?
当前回答
寻找一个Node.js/npm解决方案?试试encoding-checker:
npm install -g encoding-checker
使用
Usage: encoding-checker [-p pattern] [-i encoding] [-v]
Options:
--help Show help [boolean]
--version Show version number [boolean]
--pattern, -p, -d [default: "*"]
--ignore-encoding, -i [default: ""]
--verbose, -v [default: false]
例子
获取当前目录下所有文件的编码:
encoding-checker
返回当前目录下所有md文件的编码:
encoding-checker -p "*.md"
获取当前目录及其子文件夹中所有文件的编码(对于巨大的文件夹将需要相当长的时间;看似无响应):
encoding-checker -p "**"
更多示例请参考npm文档或官方存储库。
其他回答
如果你的Windows机器上有“git”或“Cygwin”,然后转到文件所在的文件夹并执行命令:
file *
这将为您提供该文件夹中所有文件的编码细节。
类似于上面用记事本列出的解决方案,如果你正在使用Visual Studio,你也可以在Visual Studio中打开文件。在Visual Studio中,您可以选择“File > Advanced Save Options…”
“Encoding:”组合框将明确地告诉您当前文件使用的是哪种编码。它比记事本列出了更多的文本编码,所以它在处理来自世界各地的各种文件时很有用。
就像记事本一样,你也可以从选项列表中更改编码,然后在点击“确定”后保存文件。你也可以通过Save As对话框中的“Save with encoding…”选项来选择你想要的编码(通过单击Save按钮旁边的箭头)。
寻找一个Node.js/npm解决方案?试试encoding-checker:
npm install -g encoding-checker
使用
Usage: encoding-checker [-p pattern] [-i encoding] [-v]
Options:
--help Show help [boolean]
--version Show version number [boolean]
--pattern, -p, -d [default: "*"]
--ignore-encoding, -i [default: ""]
--verbose, -v [default: false]
例子
获取当前目录下所有文件的编码:
encoding-checker
返回当前目录下所有md文件的编码:
encoding-checker -p "*.md"
获取当前目录及其子文件夹中所有文件的编码(对于巨大的文件夹将需要相当长的时间;看似无响应):
encoding-checker -p "**"
更多示例请参考npm文档或官方存储库。
(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
我写了第4个答案(在写作的时候)。但最近我在所有电脑上都安装了git,所以现在我使用@Sybren的解决方案。这是一个新的答案,使解决方案方便从powershell(没有把所有的git/usr/bin在PATH,这是太多的混乱对我来说)。
将此添加到您的配置文件中。
$global:gitbin = 'C:\Program Files\Git\usr\bin'
Set-Alias file.exe $gitbin\file.exe
并使用类似:file.exe——mime-encoding *。必须在命令中包含.exe,才能使PS别名正常工作。
但如果您不自定义PowerShell配置文件。ps1我建议你从我的开始:https://gist.github.com/yzorg/8215221/8e38fd722a3dfc526bbe4668d1f3b08eb7c08be0 并保存到~\Documents\WindowsPowerShell。在没有git的计算机上使用它是安全的,但如果找不到git,则会编写警告。
命令中的.exe也是我如何使用powershell中的C:\WINDOWS\system32\where.exe;和许多其他操作系统CLI命令是“默认隐藏”的powershell, *耸肩*。
推荐文章
- 在Sublime Text 2中使用Ctrl+D进行多个选择时,我如何跳过匹配?
- #定义WIN32_LEAN_AND_MEAN具体排除了什么?
- 最好的轻量级web服务器(只有静态内容)的Windows
- npm犯错!错误:EPERM:操作不允许,重命名
- 崇高的文本从命令行
- 如何保持Python脚本输出窗口打开?
- 使用.bat文件检查文件夹是否存在
- 如何查看Windows库(*.lib)的内容
- 在Windows中删除大文件夹最快的方法是什么?
- NPM卡住给出相同的错误EISDIR:对目录的非法操作,读取错误(本机)
- Windows 10环境变量太大
- 如何使用Windows命令行更改目录
- 如何在NERDTree中显示隐藏文件(以句点开始)?
- Objective-C for Windows
- “注册”一个.exe,这样你就可以从Windows中的任何命令行运行它