Created
November 2, 2022 01:09
-
-
Save bradwilson/3d829f618b0fb3b2f753e6310dc05422 to your computer and use it in GitHub Desktop.
Quick script to find files with UTF-8 BOMs and rewrite them without the BOM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string] $Folder = ".", | |
[string] $Filter = "*.*" | |
) | |
Get-ChildItem -Path $Folder -Recurse -File -Filter $Filter -Exclude @('obj','bin') | Foreach-Object { | |
$contents = [System.IO.File]::ReadAllBytes($_.FullName) | |
if ($contents.Length -gt 2 -and $contents[0] -eq 0xEF -and $contents[1] -eq 0xBB -and $contents[2] -eq 0xBF) { | |
Write-Host $_.FullName | |
[System.IO.File]::WriteAllBytes($_.FullName, $bytes[3..$($bytes.Length)]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment