本帖最后由 Nsqs 于 2023-8-23 10:08 编辑
- @echo off
- set "param=-noprofile -executionpolicy bypass"
- call:CodeName dir /b *.txt
- call:Merge-txtfile
- call:To-Utf8
- type uft8-txt\tmp.txt
- del uft8-txt\tmp.txt
- pause
- goto :eof
-
- :CodeName
- powershell %param% "md uft8-txt -force|out-null"
- %*|powershell -noprofile -executionpolicy bypass "process{try{$CodeName=$Input|%%{if(Test-Path $input -PathType Leaf){[byte[]]$byte=gc -Encoding byte -ReadCount 4 -TotalCount 4 -Path $input;if( $byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf ){'UTF8'}elseif($byte[0] -eq 0xfe -and $byte[1] -eq 0xff){'Unicode'}elseif($byte[0] -eq 0 -and $byte[1] -eq 0 -and $byte[2] -eq 0xfe -and $byte[3] -eq 0xff){'UTF32'}elseif($byte[0] -eq 0x2b -and $byte[1] -eq 0x2f -and $byte[2] -eq 0x76){'UTF7'}else{'ASCII'}}};if($CodeName -ne $null){('{0}={1}' -f $_,$CodeName)>>uft8-txt\tmp.txt}}catch{}}"
- goto :eof
-
-
- :Merge-txtfile
- powershell %param% "gc uft8-txt\tmp.txt|%%{$s=$_ -split '=';gc $s[0]|ac "uft8-txt\New_$($s[1]).txt" -Encoding $s[1]}"
- goto :eof
-
- :To-Utf8
- powershell %param% "gc uft8-txt\tmp.txt|%%{$s=$_ -split '=';gc $s[0]|out-file "uft8-txt\New_$($s[1])_$($s[0])" -Encoding utf8}"
- goto :eof
复制代码 运行之前测试或备份,我这边测试没有问题,运行之后会生成一个新的文件夹 |