Monday, July 30, 2018

Convert multiple text files to UTF encoding

If you have multiple files and want to convert them all into UTF (without BOM), you can try this PowerShell script.

Get-ChildItem . -recurse -File -filter *.txt* | % {
        $MyFile = Get-Content -Raw $_.Fullname
        $MyPath = $_.Fullname
        [System.IO.File]::WriteAllLines($MyPath, $MyFile, [System.Text.UTF8Encoding]($False))
}
[System.IO.File]::WriteAllLines is used instead of the more commonly used Out-File because the latter outputs UTF8-BOM instead of plain UTF.