找了个创建utf-8 带bom文件的ps代码,模仿大佬用混编写到一起- <# :
- cls&echo off&cd /d "%~dp0"&chcp 65001 >nul&set "current=%cd%"
- path %SYSTEMROOT%\System32\WindowsPowerShell\v1.0;%path%
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal \"%~f0\"|Out-String|Invoke-Expression"
- set "file=1.txt"
- (for /f "tokens=1* delims=:" %%a in ('findstr /n .* "%file%"') do (
- if "%%b" equ "{$CP936=" (
- set m=1
- ) else if "%%b" equ "{$CP950=" (
- set m=1
- ) else if "%%b" equ "{$CP0=" (
- set m=1
- ) else if "%%b" equ "$}" (
- if defined m (
- echo %%b
- )
- set m=
- )
- if defined m (
- echo=%%b
- )
- ))>>2.txt
- echo;done
- pause
- exit
- #>
- $filePath = "2.txt"
-
- # 创建文件并写入BOM
- $fileStream = [System.IO.File]::Create($filePath)
- $bom = New-Object byte[] 3
- $bom[0] = 0xEF
- $bom[1] = 0xBB
- $bom[2] = 0xBF
- $fileStream.Write($bom, 0, 3)
- $fileStream.Close()
复制代码
|