Last active
September 7, 2018 02:07
-
-
Save iamleeky/c76c3eb002b8b21c5df01bbb141cca3d to your computer and use it in GitHub Desktop.
Re-save as UTF-8 encoded files
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
| ###################################################################### | |
| # Script to re-save a file or all files recursively in a directory | |
| # as URF-8 encoded file or files | |
| # | |
| # Author: iamleeky@gmail.com | |
| ###################################################################### | |
| # Target file or directory | |
| $TargetPath = "C:\yourpath" | |
| # Target name formats | |
| $Filter = @("*.asp","*.asa") | |
| # If you want to remove UTF8 signature - BOM (Byte Order Mark), then set it as $true | |
| $RemoveBom = $false | |
| Get-ChildItem $TargetPath -recurse -Include $Filter | ForEach-Object { | |
| $content = $_ | Get-Content | |
| Set-Content -PassThru $_.Fullname $content -Encoding UTF8 -Force | |
| if ($RemoveBom) | |
| { | |
| $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $false | |
| [System.IO.File]::WriteAllLines($_.Fullname, $content, $Utf8NoBomEncoding) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment