标题: [文本处理] 批处理怎样查找“UTF-8”编码的文件? [打印本页]
作者: 屡败屡战 时间: 2018-7-23 10:21 标题: 批处理怎样查找“UTF-8”编码的文件?
如何能从当前文件夹下(含子目录)搜索出“UTF-8”编码的文件?
作者: CrLf 时间: 2018-7-23 15:01
猜测某个文件的编码可以用 enca,至于批量判断,楼主可以自己试试- enca.exe -L zh_CN -g 新建文本文档.txt
复制代码
作者: 屡败屡战 时间: 2018-7-24 09:53
我下载了enca.exe,与UTF-8文件(测试文件)放在一起,试着运行批处理代码,伹毫无反应,不知咋回亊??
作者: 屡败屡战 时间: 2018-7-24 22:09
问下,查找utf-8文件,有办法吗?
作者: Batcher 时间: 2018-7-25 09:08
回复 3# 屡败屡战
不要双击执行。打开一个CMD窗口执行,这样能看到报错信息。
作者: 屡败屡战 时间: 2018-7-25 13:34
我的文挡里有大量utf-8文件,在不知道的情况下,只要改变一下内容,很容易变成乱码文件,让人叫苦不迭!
问下,查找utf-8文件,有办法吗?反正我试遍了,没什么好办法?
另外问下,由utf-8编码导致的乱码能否再恢复过来,可以识别文字。
作者: Batcher 时间: 2018-7-26 15:10
test.ps1- function Get-FileEncoding {
- [CmdletBinding()] Param (
- [Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string]$Path
- )
-
- [byte[]]$byte = get-content -Encoding byte -ReadCount 4 -TotalCount 4 -Path $Path
-
- if ( $byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf ) {
- Write-Output 'UTF8'
- }
- elseif ($byte[0] -eq 0xfe -and $byte[1] -eq 0xff) {
- Write-Output 'Unicode'
- }
- elseif ($byte[0] -eq 0 -and $byte[1] -eq 0 -and $byte[2] -eq 0xfe -and $byte[3] -eq 0xff) {
- Write-Output 'UTF32'
- }
- elseif ($byte[0] -eq 0x2b -and $byte[1] -eq 0x2f -and $byte[2] -eq 0x76) {
- Write-Output 'UTF7'
- } else {
- Write-Output 'ASCII'
- }
- }
-
- Get-ChildItem -Path "C:\Test\" -Include "*.txt" -Recurse | % {
- $EncodeName = Get-FileEncoding $_.FullName
- if ( $EncodeName -eq "UTF8" ) {
- $_.FullName
- }
- }
复制代码
test.bat- @echo off
- powershell -f test.ps1 > UTF8_List.log
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |