Page 1 of 1

How to read a file in UTF-8 and remove a BOM in batch script?

Posted: 2021-Oct-04, 11:25 am
by PiotrMP006
Hi

How to read a file in UTF-8 and remove a BOM in batch script?

Re: How to read a file in UTF-8 and remove a BOM in batch script?

Posted: 2022-Feb-05, 5:11 pm
by Simon Sheppard
Some answers to this here

If you're using PowerShell [Core] version 6 or higher, you get BOM-less UTF-8 files by default
https://stackoverflow.com/questions/400 ... 4#40098904

PowerShell is much better suited to the task of dealing with encodings than batch:

To remove embedded UTF-8 BOM characters from source files:

Code: Select all

$files=get-childitem -Path . -Include @("*.h","*.cpp") -Recurse
foreach ($f in $files){
 (Get-Content $f.PSPath) | 
 Foreach-Object {$_ -replace "\xEF\xBB\xBF", ""} | 
 Set-Content $f.PSPath
}
via SO